Mongo DB: Iterate through a MongoCollection

This is specifically for Mongo 3.x, where MongoCollection is preferred over DBCollection. Adding for personal archiving.


MongoCollection mongoCollection =
getMongoCollection(databaseName, collectionName);

FindIterable documents =
mongoCollection.find(eq(COLUMN, "lastName"))
.sort(ascending("lastname"));

for (Document document : documents) {
...
}


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *