1

I have collection as: col1

{"_id":"5c3ea35651166f3refsfd5",
"environment": "production",
"application": ['cloud', 'android', 'finance']},

{"_id":"5c3ea35651166f3refsfd6",
"environment": "production",
"application": ['banking', 'network', 'finance']}

I want to project the data only if the application/s in collection matches with the application in the list of ['cloud', 'database', 'booking']. In this case, I should be able to get only first document as it has 'cloud' in both document as well as in list.

I need to use aggregation. But I am not getting correct direction..

1 Answer 1

1

You can use $in query operator

col1.aggregate([
  { '$match': { 'application': { '$in': ['cloud', 'database', 'booking'] }}},
  { '$project': { 'environment': 1, 'application':1 }}
])
Sign up to request clarification or add additional context in comments.

3 Comments

But the values in list changes according to user, so I should not use fixed list.
You can dynamically put the lst array.
Oh! my bad. Thank you.

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.