Im trying to read a (mongo)userdatabase with java. On the tutorial page I saw how to read the whole collection. I can do something like that:
DBCursor cu
You can query desired data directly:
BasicDBObject query = new BasicDBObject();
query.put("name", "user");
query.put("password", "[YOUR ENCRYPTED PASSWORD HERE]");
DBCollection collection = db.getCollection("yourcollectionname");
DBCursor cursor = collection.find(query);
while (cursor.hasNext()) {
//do something with cursor.next();
}
As was suggested you need to check count of results returned by find() method to make sure only single record matches your query.