I'm running a query on a collection with documents like these.
{"name": "Daniel", "tags": ["person", "owner", "father"]},
{"name": "Jane", "tags": ["person", "owner", "mother"]},
{"name": "Jimmy", "tags": ["person", "owner", "son"]}
Now, if I want to find all documents matching the tags person AND owner I would do something like this
var match = ['person', 'owner'];
model.find({'tags': {$all: match}});
Now I need to do the following:
- When match has values, return all document matching those (This is done)
- When match is empty [ ], return all documents.
What's the most efficient way to do that in a single query?
Thanks in advance,
D