How to find length of the array mongodb

后端 未结 1 445
暖寄归人
暖寄归人 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)
提交回复
热议问题