Документ
{
"_id" : ObjectId("5e33fee6bc9987050fc40550"),
"uuid" : "XXXXX",
"data" : [
{
"words" : [
"facebook"
],
"status" : 0,
"uid" : "12345",
"details" : {}
},
{
"words" : [
"youtube",
"facebook"
],
"status" : 0,
"uid" : "34567",
"details" : {}
}
]
}
Запрос
var wordsList = ["facebook"];
db.collectionName.find({ 'data.words' : { "$in" : wordsList }})
.map(function(list){
var results = [];
list.data.forEach(function (dataListElement){
if(dataListElement.words.filter(value => wordsList.includes(value)).length > 0){
results.push(dataListElement);
}
})
return results;
}
);
Результат
[
[
{
"words" : [
"facebook"
],
"status" : 0,
"uid" : "12345",
"details" : {}
},
{
"words" : [
"youtube",
"facebook"
],
"status" : 0,
"uid" : "34567",
"details" : {}
}
]
]