I have 5 collections C1, C2, C3, C4 and N5 each having a last_updated value.
db.getCollectionNames().filter(function(c){ return c.indexOf('C')==0})
will return me all the collections that start with "C".
Is it possible to go one step ahead and do a filter based on "last_updated" column so that i will get all "C" collections that are updated yesterday.
something like this
db.getCollectionNames().filter(function(c){ return (db.c.find({update_on: "01-Dec-2014"}).count()
> 1)});
Eventhough the query runs fine its not yeilding any result.
You need to return
true
even if one record is present is present in the collection for the queried date.Second,
db.c
is resolved to valuec
,Therefore finding the count of a collection namedc
, which does not exist. To resolvec
as a variable, we need to use it asdb[c]
.The modified code below would do that: