I'm new to mongoDB and have set up a java application to communicate with my db. I only have one collection in my db that contains several documents. Is there a way that I can make a single query to grab my collection and then somehow access all the fields in each document?
I attempted to create a query and then add all my DBObjects to an ArrayList. But once I've done that, I can't figure out how I can access the data in each document.
Here's what I have so far:
ArrayList<DBObject> docs = new ArrayList<DBObject>();
DBCollection coll = db.getCollection("testCollection");
DBCursor cursor = coll.find();
try {
while(cursor.hasNext()) {
docs.add(cursor.next());
}
} finally {
cursor.close();
}
//how do I access everything in my docs???
docs.get(0).find("id", 1);