How to find length of the array mongodb

后端 未结 1 438
暖寄归人
暖寄归人 2020-12-10 19:09

I have such this type of structure of my database. I want to find number of documents my \"JAN\" array contains. I am trying to do in different way but nothing works. That w

相关标签:
1条回答
  • 2020-12-10 19:35

    You can use $size operator to find the length of the array

    db.collection.aggregate([
      {
        "$project": {
          "totalJan": {
            "$size": "$2017.JAN"
          }
        }
      }
    ])
    

    MongoPlayground

    0 讨论(0)
提交回复
热议问题