This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
collection.update(new BasicDBObject("_id", "jo"), | |
new BasicDBObject("$set", new BasicDBObject("phone", "5559874321"))); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DBObject jo = // get the document representing jo | |
jo.put("name", "Jo In Disguise"); // replace the old name with the new one | |
collection.update(new BasicDBObject("_id", "jo"), // find jo by ID | |
jo); // set the document in the DB to the new document for Jo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
collection.createIndex(new BasicDBObject("fieldToIndex", 1)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DBObject findLondoners = new BasicDBObject("address.city", "London"); | |
collection.find(findLondoners)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DBCursor results = collection.find(new BasicDBObject("name", new BasicDBObject("$gt", 10))); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DBCursor results = collection.find(new BasicDBObject("numberOfOrders", new BasicDBObject("$gt", 10))); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DBCursor results = collection.find(new BasicDBObject("name", "SomeName"), | |
new BasicDBObject("address", 0)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DBCursor results = collection.find(new BasicDBObject("name", "SomeName"), | |
new BasicDBObject("name", 1)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for (DBObject result : results) { | |
// do something with each result | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
results.size(); |