'Mongodb query to search all nested objects of array is empty

I am trying to achieve one query for below data.

[
  {
    "blocks": [
      {
        "issues": {}
      },
      {
        "issues": {
          "dt": "dt"
        }
      }
    ]
  },
  {
    "blocks": [
      {
        "issues": {
          "ext": "data"
        }
      }
    ]
  },
  {
    "blocks": [
      {
        "issues": {}
      }
    ]
  }
]

So, Here are case

from any documents, from any blocks, if any issues object is not empty then skip that document. If blocks having all issues are empty object then return that document.

I tried @elementMatch, $eq, $nin, $ne, @all etc way but not able to solve.

any help would be great



Solution 1:[1]

Maybe something like this:

 db.collection.find({
 $nor: [
   {
    "blocks": {
      $elemMatch: {
        "issues": {
          $nin: [
            {}
          ]
        }
      }
    }
  }
]
})

Explained: Search documents where there is only blocks.issues: {}

playground

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1