MongoDB $elemMatch $in

前端 未结 3 1224
感动是毒
感动是毒 2021-02-04 02:24

So, I have a database with a load of arrays in documents in it. I want to find entire documents where my queries are an exact match for one or more array elements using $i

3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-02-04 03:04

    You can use different syntax than the one you're trying that achieves the same result but doesn't run into the limitation in SERVER-3544.

    Use this syntax:

    db.collection.find({ "unusual": {"$elemMatch":{"defindex":363,"_particleEffect":{"$in":[6,19]}  }} })
    

    This will match any document which has an array element with both 313 and either 6 or 19.

    It also works with {$in:[]} for both defindex and _particleEffect, as long as you intend to match any combination of the two lists.

    db.collection.find({ "unusual": {"$elemMatch":{"defindex":{"$in":[313,363]},"_particleEffect":{"$in":[6,19]}  }} })
    

提交回复
热议问题