Find document with array that contains a specific value

前端 未结 10 1434
猫巷女王i
猫巷女王i 2020-11-22 04:06

If I have this schema...

person = {
    name : String,
    favoriteFoods : Array
}

... where the favoriteFoods array is popula

10条回答
  •  一整个雨季
    2020-11-22 04:34

    Incase of lookup_food_array is array.

    match_stage["favoriteFoods"] = {'$elemMatch': {'$in': lookup_food_array}}
    

    Incase of lookup_food_array is string.

    match_stage["favoriteFoods"] = {'$elemMatch': lookup_food_string}
    

提交回复
热议问题