I'm new using MongoDB, and I don't know how to solve the next problem:
I have a collection of documents like this:
{
"URL": "www.stackoverflow.com",
"TAGS": [
{"NAME": "question", "VOTES": 3},
{"NAME": "answer", "VOTES": 5},
{"NAME": "problem", "VOTES": 2}
]
}
First of all, I wanted all the Urls that have all the tags given in a list. I have solved this by quering:
db.links.find( { "Tags.Name" : { $all: ["question","answers"] } } );
But this query return the whole correct document, insted of only the correct document with only the tags I have asked for.
The result I'm looking for is:
{
"URL": "www.stackoverflow.com",
"TAGS": [{"NAME": "question", "VOTES": 3},
{"NAME": "answer", "VOTES": 5}]
}
and not:
{
"URL": "www.stackoverflow.com",
"TAGS": [{"NAME": "question", "VOTES": 3},
{"NAME": "answer", "VOTES": 5},
{"NAME": "problem", "VOTES": 2}]
}
Because I've only asked for the tags ["question","answers"].
I thought about using MapReduce or parsing the resultset, but I don't know if it is the correct way of solving the problem. Maybe there is a builtin function that solve it more efficiently.
Thanks!