Query for documents where array size is greater than 1

后端 未结 14 2150
北海茫月
北海茫月 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:36

    Although the above answers all work, What you originally tried to do was the correct way, however you just have the syntax backwards (switch "$size" and "$gt")..

    Correct:

    db.collection.find({items: {$gt: {$size: 1}}})
    

    Incorrect:

    db.collection.find({items: {$size: {$gt: 1}}})
    

提交回复
热议问题