This file contains hidden or 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
| { | |
| "id": "", | |
| "meh": { | |
| "feh": "", | |
| "bleh": "" | |
| }, | |
| "tom": { | |
| "tum": "", | |
| "dick": { | |
| "harry": "", |
This file contains hidden or 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
| public class TestDBObjectFactory { | |
| public static DBObject createJson() { | |
| DBObject doc = new BasicDBObject(); | |
| doc.put("_id", "someGeneratedValue"); | |
| doc.put("nameOne", "valueOne"); | |
| doc.put("nameTwo", "valueTwo"); | |
| DBObject sub = new BasicDBObject(); | |
| sub.put("subNameOne", "subValueOne"); | |
| sub.put("subNameTwo", "subValueTwo"); |
This file contains hidden or 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 test = TestDBObjectFactory.createJson(); | |
| DBCollection coll = db.getCollection("tests"); | |
| DBCursor cur = coll.find(); | |
| while(cur.hasNext()) { | |
| DBObject current = cur.next(); | |
| Set symmetricDiff = new HashSet(test.keySet()); | |
| symmetricDiff.addAll(current.keySet()); | |
| Set tmp = new HashSet(test.keySet()); |
This file contains hidden or 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
| cfg = { | |
| _id : "myset", | |
| members : [ | |
| { _id : 0, host : "host0.meh.com:27017", priority : 10}, | |
| { _id : 1, host : "host1.meh.com:27017", votes : 2} | |
| ] | |
| } | |
| rs.initiate(cfg) | |
| "...Config now saved locally. Should come online in about a minute..." |
This file contains hidden or 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
| rs.status() |
This file contains hidden or 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
| echo mymongosupersecret mykey |
This file contains hidden or 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
| use admin | |
| db.shutdownServer() |
This file contains hidden or 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
| mongod --keyFile mykey --replSet myset |
This file contains hidden or 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
| use admin | |
| db.addUser("mongouser", "mongopass") | |
| use admin | |
| db.auth("mongouser", "mongopass") | |
| use mydb | |
| db.addUser("mydbuser", "mydbpass") | |
| db.auth("mydbuser", "mydbpass") |
This file contains hidden or 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
| use itemCollection | |
| db.itemCollection.insert({ | |
| "id" : "1", | |
| "somefield" : "blah", | |
| "someotherfield" : "meh", | |
| "notanotherfield" : "feh", | |
| "items" : ["item0", "item1", "item2", "item2"] | |
| }) | |
| db.itemCollection.insert({ | |
| "id" : "2", |