-
Type: Bug
-
Resolution: Done
-
Priority: Minor - P4
-
Affects Version/s: None
-
Component/s: None
-
None
This method is not properly documented and there aren't any examples in the tutorial. At first, I tried to pass a DBList of the keys in. Please make sure to specify that you pass in an empty DBObject to the find method to walk all docs in the collection.
DBCursor find(DBObject ref, DBObject keys)
Here is my test/sample code:
final Mongo db = new Mongo("localhost", "myDb");
final DBCollection col = db.getCollection("myCollection");
final BasicDBObject keys = new BasicDBObject();
keys.put("_id", 1);
final DBCursor cur = col.find(new BasicDBObject(), keys);
while (cur.hasNext())
{ BasicDBObject doc = (BasicDBObject)cur.next(); for (final String field : doc.keySet()) System.out.println(field); }I would also document that the _ns field is always returned.