MongoDB aggregate query with a where in node.js -
MongoDB aggregate query with a where in node.js -
i have next mongodb query in node.js gives me list of unique zip codes count of how many times zip code appears in database.
collection.aggregate( [ { $group: { _id: "$location.zip", count: { $sum: 1 } } }, { $sort: { _id: 1 } }, { $match: { count: { $gt: 1 } } } ], function ( lookuperr, lookupdata ) { if (lookuperr) { res.send(lookuperr); return; } res.send(lookupdata.sort()); }); });
how can query modified homecoming 1 specific zip code? i've tried status clause have not been able work.
aggregations require filtered results can done $match
operator. without tweaking have, suggest sticking in $match
zip code want returned @ top of aggregation list.
collection.aggregate( [ { $match: { zip: 47421 } }, { $group: { ...
this illustration result in every aggregation operation after $match
working on only info set returned $match
of zip
key value 47421
.
node.js mongodb
Comments
Post a Comment