I am trying to combine regular expression queries and inline objects and fail. I either click the restriction on mongodb, or just get something a little wrong, maybe some of them came across this. The documentation, of course, does not cover this case.
requested data:
{ "_id" : ObjectId("4f94fe633004c1ef4d892314"), "productname" : "lightbulb", "availability" : [ { "country" : "USA", "storeCode" : "abc-1234" }, { "country" : "USA", "storeCode" : "xzy-6784" }, { "country" : "USA", "storeCode" : "abc-3454" }, { "country" : "CANADA", "storeCode" : "abc-6845" } ] }
Suppose a collection contains only one entry
This query returns 1:
db.testCol.find({"availability":{"country" : "USA","storeCode":"xzy-6784"}}).count();
This query returns 1:
db.testCol.find({"availability.storeCode":/.*/}).count();
But this query returns 0 :
db.testCol.find({"availability":{"country" : "USA","storeCode":/.*/}}).count();
Does anyone understand why? This is mistake?
thanks
source share