MongoDB $elemMatch $in

前端 未结 3 1227
感动是毒
感动是毒 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]}  }} })
    
    0 讨论(0)
  • 2021-02-04 03:04

    Just try this (Tested)

    {
    "unusual":  { 
            $all:[{
                $elemMatch:{"defindex":313},
                $elemMatch:{"_particleEffect":6}
            }]
        }
    }
    
    0 讨论(0)
  • 2021-02-04 03:21

    https://jira.mongodb.org/browse/SERVER-3544

    Welp, did a LOT of digging and it looks like that answers my question. You cannot do $in $elemmatch at this time.

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