performance - Faster query by value -
i want query mongodb find, in results
top level document, how many nested documents of have value 0
.
for instance, in collection:
{name: "mary", results: {"foo" : 0, "bar" : 8}} {name: "bob", results: {"baz" : 9, "qux" : 0}} {name: "leia", results: {"foo" : 9, "norf" : 5}}
my query should return 2
, because 2 of documents have 0
value of nested document of results
.
here's attempt
db.collection.find({$where : function() { (var key in this.results) { if (this.results[key] === 0) { return true;} } return false; } })
which works on above dataset, slow. real data 100k documents, each having 500 nested documents inside results
, , above query takes few minutes. possible design query in faster way?
there no way it, other 1 doing.
you can change schema or use aggregations don't think want.
there post can check here: mongodb: find embedded value
Comments
Post a Comment