1

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

1 Answer 1

1

Maybe something like this:

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

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

playground

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.