I am giving up searching and reading for a way to return documents where all entries exists in an array.
It seems $in returns matches based on "any" and $all returns what I want but only the field (not the whole document)
The result I want is all documents that have all tags provided in the search.
The model looks like this:
var AssetSchema = new Schema({
name: String,
url: String,
tags: [String]
});
A simple DB looks like this:
[
{
_id: "55fd2974a3fce70d58c23bd0",
name: "Lord of the rings",
__v: 0,
tags: [
"channel:svt",
"user:12345"
]
},
{
_id: "55fd29b9a3fce70d58c23bd1",
name: "Always Ultra",
__v: 0,
tags: [
"channel:svt",
"user:12346"
]
}
]
The code looks like this:
Asset.find(({tags: {$in: ["user:123456","channel:svt"]}})
.exec(function(err, assets) {
console.log(assets);
});