Skip to content

Instantly share code, notes, and snippets.

@ojas
Last active December 24, 2015 00:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ojas/6719980 to your computer and use it in GitHub Desktop.
Save ojas/6719980 to your computer and use it in GitHub Desktop.
MongoDB tips
# Load a MongoDB collection with test data
## Let's load some sample data in mongo
curl -s 'http://www.json-generator.com/j/cdQGOkHUoi?indent=4' | mongoimport --db playpen --collection people --jsonArray
mongo playpen
## Create facets based on this [walkthru](http://blog.mongodb.org/post/59757486344/faceted-search-with-mongodb)
db.people.ensureIndex({"facets3.age" : 1})
db.people.ensureIndex({"facets3.gender" : 1})
db.people.find().forEach( function(doc) {
db.people.update({_id:doc._id}, {$set:{"facets3": { age : [ doc.age ], gender : [ doc.gender ] } }});
});
db.people.find({ 'facets3.age' : 39 }).explain()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment