3

Lets say in my database :

{
  domains:[A, B, C],
  id: 1
},
{
  domains:[B, C],
  id: 2
},
{
  domains:[A],
  id: 3
},
{
  domains:[B, D],
  id: 4
}

I want to search query like domains: [A, D]. Basically i want to match at least one element not for all element.

My expecting answer is

{
  domains:[A, B, C],
  id: 1
},
{
  domains:[A],
  id: 3
},
{
  domains:[B, D],
  id: 4
}

Cause A and D(at least one) are found into this objects.

I want to retrieve questions, which matches the at least one topics?

1 Answer 1

4

You can use $in operator in this way:

yourModel.find({
  "domains": {
    "$in": [
      "A",
      "D"
    ]
  }
})

Example here

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

2 Comments

Works well. Thanks a lot J.F.
J.F. I updated my question. I added a second question.Can you answer the question?

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.