I have a mongo request that performs a batch operation on documents.
I got almost expected results, except that I want to clarify the results without empty or null values.
Currently my query looks like this:
db.productMetadata.aggregate([{$group:{"_id":{"color":"$productAttribute.colour","gender":"$productAttribute.gender"},"count" : {$sum : 1}}}]);
And the results look something like this:
{ "_id" : { "color" : "BLUE", "gender" : "MEN" }, "count" : 1 } { "_id" : { }, "count" : 4 } { "_id" : { "color" : "NA", "gender" : "WOMEN" }, "count" : 1 } { "_id" : { "color" : "BLACK", "gender" : "MEN" }, "count" : 1 } { "_id" : { "color" : "BROWN", "gender" : "WOMEN" }, "count" : 1 } { "_id" : { "gender" : "MEN" }, "count" : 2 } { "_id" : { "color" : "BEIGE", "gender" : "MEN" }, "count" : 1 } { "_id" : { "color" : "BROWN", "gender" : "MEN" }, "count" : 1 }
I want to delete rows if any of the group values ββby field is empty or zero in the actual database data.
Excluded results should look something like this:
{ "_id" : { "color" : "BLUE", "gender" : "MEN" }, "count" : 1 } { "_id" : { "color" : "NA", "gender" : "WOMEN" }, "count" : 1 } { "_id" : { "color" : "BLACK", "gender" : "MEN" }, "count" : 1 } { "_id" : { "color" : "BROWN", "gender" : "WOMEN" }, "count" : 1 } { "_id" : { "color" : "BEIGE", "gender" : "MEN" }, "count" : 1 } { "_id" : { "color" : "BROWN", "gender" : "MEN" }, "count" : 1 }
mongodb mongodb-query aggregation-framework mongodb-aggregation
starkk92
source share