Procure por valor de texto em todas as coleções do MongoDB

//Given a field name and search text, search it in all MongoDB collections

var collections = db.getCollectionNames();
var targetValue = "some string";

collections
.forEach(function (collectionName) {
var collection = db.getCollection(collectionName);
var count = collection.find({"<field name>": targetValue}).count();
if (count > 0) {
print('Collection ' + collectionName + 'contains ' + count + ' references to ' + targetValue);
}
});