Skip to content

Instantly share code, notes, and snippets.

@citmusa
Last active December 29, 2015 14:19
Show Gist options
  • Save citmusa/7682959 to your computer and use it in GitHub Desktop.
Save citmusa/7682959 to your computer and use it in GitHub Desktop.
MONGO DB
db.collection.find({ query },{"field to show": true, "field to show": true})
db.collection.find({ query },{"field to show": true, "_id": false })
db.products.find({"field_name":{$exists:true}})
mr = db.runCommand({
"mapreduce" : "collection_name",
"map" : function() {
for (var key in this) { emit(key, null); }
},
"reduce" : function(key, stuff) { return null; },
"out": "things" + "_keys"
})
#Then run
db[mr.result].distinct("_id")
["foo", "bar", "baz", "_id", ...]
db.collection.update({ query }, { $rename: { "old name": "new name" }}, false, true)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment