I am trying to determine which collections have a document that matches a certain pattern.
I based the below off this answer, however instead of printing the result, what looks to be a function definition gets printed.
db.getCollectionNames().forEach(function(collname) {
// find the last item in a collection
var isPresent = db[collname].find().sort({_id:-1}).limit(1);
// check that it's not empty
if (isPresent.hasNext()) {
var TheCoo = db[collname].find({"_id":{ $regex: 'thecoolest.com'} });
printjson(TheCoo);
printjson(collname);
}
})
Here is a sample of the output:
{
"_mongo" : connection to xxx.xxx.xxx,
"_db" : etf,
"_collection" : coo.data,
"_ns" : "coo.data",
"_query" : {
"_id" : {
"$regex" : "thecoolest.com"
}
},
"_fields" : null,
"_limit" : 0,
"_skip" : 0,
"_batchSize" : 0,...