Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

mongodb count conditional array items

db.collection.aggregate([
  { "$project": {
    "total": {
      "$size": {
        "$filter": {
          "input": "$Array",
          "cond": { "$eq": [ "$$this.field1", "a" ] }
        }
      }
    }
  }}
])
 
PREVIOUS NEXT
Tagged: #mongodb #count #conditional #array #items
ADD COMMENT
Topic
Name
1+7 =