I had been trying to write an aggregation pipeline in MongoDB which uses a lookup stage with a sub pipeline. In that pipeline, I am trying to match a field in an array in the document with an array of strings. But it seems to be not working. I get an empty result(No documents).
Following is a document from the collection called 'card' :
{
"_id": "5fbff18be1157d5f8c6089f2",
"keywords": [{
"type": "topic",
"value": "benny"
}, {
"type": "tag",
"value": "bo"
}, {
"type": "tag",
"value": "bo"
}],
"name": "tasty_steel_car"}
In this, I am trying to match the field: 'value' inside the keywords with the following query :
{
'from': 'cards',
'let': {
'keywordList': '$keywords'
},
'pipeline': [
{
"$match": {
"$expr": {
$and: [
{ "$in": [ "$keywords.value", ['benny'] ] }
]
}
}
}
],
'as': 'cards'
}
What am I doing wrong here?
The following part doesn't seem to work :
{ "$in": [ "$keywords.value", ['benny'] ] }
Even the following doesn't seem to be working:
db.cards.find({
$expr: {
$in: [ "$keywords.value", ["benny"] ]
}
})