I have the following collections:
Patterns: {idPattern, name, description}
SelectedPatterns: {user, idPatterns}
I am trying to do a query that retrieves all the pattern info (idPattern, name, description
) for a given set of users. For instance, imagine the database info is as follows:
Patterns:
{"idPattern":1, "name":"name1","description":"desc1"}
{"idPattern":2, "name":"name2","description":"desc2"}
{"idPattern":3, "name":"name3","description":"desc3"}
{"idPattern":4, "name":"name4","description":"desc4"}
SelectedPatterns:
{"user":"user1", "idPatterns":[1,2]}
{"user":"user2", "idPatterns":[2,3]}
The result of the query for user1
should look something like this this:
[{"idPattern":1, "name":"name1","description":"desc1"},
{"idPattern":2, "name":"name2","description":"desc2"}]
I know how to do this with some Python
logic and two Mongo
queries but this is quite inefficient, so my question is, could this information be retrieved with a single Mongo
query?