Search for ObjectId in Mongo without knowing the collection name

db.getCollectionNames().forEach(function(collName) {
   var doc = db.getCollection(collName).findOne({"_id" : ObjectId("4f62635623809b75e6b8853c")});
   if(doc != null) print(doc._id + " was found in " + collName); 
}); 

(c)redits

Leave a Reply

Your email address will not be published. Required fields are marked *