RawSushi's Tech Journal
My online tech scrapbook where I keep my notes in case I need to look them up later
Sunday, July 15, 2012
Mongo DB: Java API Get Object by ID
You'll get an error if you try to do something along the lines of "{_id: xxxxx}".
This is how it's done:
BasicDBObject searchCriteria = new BasicDBObject("_id", new ObjectId(id));
DBObject dbObj = collection.findOne(searchCriteria);
No comments:
Post a Comment
Newer Post
Older Post
Home
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment