I'm working on updating a pipeline that isn't working properly at the moment. I'm trying to grab data that matches the following specifications, however Nodejs is 'requiring' me to use variable assignments for my different aggregations. I'm only looking to use $and at the match stage, and remove all other operators from the aggregation. The simplified match query that I've came up with looks like the following:
{
$and:[
{templateName: 'Bug Log'},
{
'classification': {
'$elemMatch': {
'$or': [
{
'name': 'Bug',
'value': true
},
{
'name': 'Log',
'value': true
},
]
}
},
},
],
}
However Nodejs if forcing a variable assignment within the function that I am using, so removing '$and' or '$or' throws an error within VScode.
return {
templateName: query.TEMPLATENAME,
pipelines: {
$and: [ //how do I remove this and block
{
...matchPipe(id),
},
...pipe2,
],
},
};
return {
classification: {
$elemMatch: {
$or: [ //how do i remove this $or block
...args,
],
},
},
};
}
I've gotten around the VSCode error, however the functions will treat the return statements as arrays and will replace the missing '$or'/'$and' with number values, as if it were an array or it won't allow me to perform this operation at all. I've included the returned query after removing the '$or' statement from the second return statement below for reference. How do I get around this error?
{"$and":[
{"templateName":"Bug Log","$and":[
{"classification":{"$elemMatch":{"0":{"nodePath":{}}}}},
{"classification":{"$elemMatch":{"0":{"name":"Bug"},"1":{"value":true}}}},{"classification":{"$elemMatch":{"0":{"name":"Log","value":true}}}}]}]}}
Thank you for all and any help