1

I have objects in the document that look's like:
my collections
I want to get only the elements from the 'transactions' array that their inside field 'isMatched' == false
I tried:

db.myCollection.find(
{ "transactions.isMatched": false } ,
    { "transactions.isMatched": 1 
    })

But i got all the array elements:
results

What is the appropriate query for this?

1 Answer 1

1

You can achieve this with aggregation. $filter helps to eliminate unwanted objects.

db.collection.aggregate([
  {
    $project: {
      company: 1,
      transaction: {
        $filter: {
          input: "$transaction",
          cond: {
            $eq: [
              "$$this.isMatched",
              false
            ]
          }
        }
      }
    }
  }
])

Working Mongo 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.