Skip to content

Instantly share code, notes, and snippets.

@moonhouse
Created July 16, 2014 14:51
Show Gist options
  • Select an option

  • Save moonhouse/2dbad54004c7d724e981 to your computer and use it in GitHub Desktop.

Select an option

Save moonhouse/2dbad54004c7d724e981 to your computer and use it in GitHub Desktop.
List objects with a certain id in MongoDB regardless of collection
var searchId = function (objId) {
coll = db.getCollectionNames();
coll.forEach(function(collName) {
obj = db[collName].findOne({'_id': ObjectId(objId)});
if (obj !== null) {
print(collName + " " + objId);
}
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment