0

I am trying match documents where all items in field colors included in query list provided.

   {id: 1, colors: ["red"] },
   {id: 2, colors: ["blue", "red"] },
   {id: 3, colors: ["red", "blue", "green" ] },
   {id: 4, colors: ["black", "blue", "green" ] },

if the query [red] it should match items 1 if query [red, blue] it should match 1,2 if query [blue, green, red] it should match 1,2,3

all items in colors field should be in the query list

How can I do it in Mongodb

0

1 Answer 1

1

Query

  • i think you want colors to be subset of the query

Playmongo

aggregate(
[{"$match": {"$expr": {"$setIsSubset": ["$colors", ["red", "blue"]]}}}])
Sign up to request clarification or add additional context in comments.

4 Comments

Thanks for your replay, This solves the second half of my implementation for subscription/notification. user can subscribe for tags on post, every subscription is a list of strings like so [ ["cityName", "flat", "rent"], ["cityName", "car", "sale", "honda"], ["car", "sale"], [ "electronics", "tv", "sale"] ] with your answer the server can send notification on new post if the list of tags in post match any of subscription arrays for the user now how can I fetch the list of posts base on subscription arrays of the user, so user can see all related posts on his feeds. Thanks
i am confused a bit, i think it will be easier to create another question, with the new data, what query should do, and the expected output
can you please tell about this solution if it is efficient ? stackoverflow.com/q/73759299/9487632

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.