Query for documents where array size is greater than 1

后端 未结 14 1947
北海茫月
北海茫月 2020-11-22 03:02

I have a MongoDB collection with documents in the following format:

{
  \"_id\" : ObjectId(\"4e8ae86d08101908e1000001\"),
  \"name\" : [\"Name\"],
  \"zipcod         


        
14条回答
  •  遇见更好的自我
    2020-11-22 03:22

    You can MongoDB aggregation to do the task:

    db.collection.aggregate([
      {
        $addFields: {
          arrayLength: {$size: '$array'}
        },
      },
      {
        $match: {
          arrayLength: {$gt: 1}
        },
      },
    ])
    

提交回复
热议问题