MongoDB object property $exists in nested array

前端 未结 1 1234
故里飘歌
故里飘歌 2021-02-20 15:01

I have a folowing object structure in my db collection:

{
    \"name\" : \"test\",
    \"code\" : \"test\",
    \"attributes\" : [ 
        {
            \"name\         


        
1条回答
  •  醉梦人生
    2021-02-20 15:09

    The $elemMatch operator matches documents that contain an array field with at least one element that matches all the specified query criteria.

    This query work for me:

    db.getCollection('testeur').find({ "attributes": {
            $exists: true, 
            $ne: [],
            $elemMatch: { "value": {$exists: false } } 
        }
    })
    

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