Last active
December 24, 2015 00:58
-
-
Save ojas/6719980 to your computer and use it in GitHub Desktop.
MongoDB tips
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
# 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