I have a collection like
{ "_id": "201503110040020021", "Line": "1", // several documents may have this Line value "LineStart": ISODate("2015-03-11T06:49:35.000Z"), "SSCEXPEND": [{ "Secuence": 10, "Title": 1, }, { "Secuence": 183, "Title": 613, }, ... ], } { "_id": "201503110040020022", "Line": "1", // several documents may have this Line value "LineStart": ISODate("2015-03-11T06:49:35.000Z"), "SSCEXPEND": [{ "Secuence": 10, "Title": 1, }, ], }
SSCEXPEND is an array. I am trying to calculate the size of an SSC array and a project if the number is greater than or equal to 2. My query is like this
db.entity.aggregate( [ { $project: { SSCEXPEND_count: {$size: "$SSCEXPEND"} } }, { $match: { "SSCEXPEND_count2": {$gte: ["$SSCEXPEND_count",2]} } } ] )
I expect the output to be only the first document whose array size is greater than 2.
Part of the project is working fine, and I can get the calculations, but I only need to project those that have an account greater than or equal to two, but my part of the match does not work. Can someone lead me like I'm wrong?
source share