Data is as follows:
` { "_id" : 1, "item" : "abc1", qty: 300 }
{ "_id" : 2, "item" : "abc2", qty: 200 }
{ "_id" : 3, "item" : "xyz1", qty: 250 }
`
Function is as follows:
abd(v){
return v;
}
Now I need to calculate collections with the qty equaling 200 using aggregation pipes, for example:
{$project:{valu e:{
$cond: {
if: { $eq: [ db.eval("abc('$ qty')") , 200 ] }, then: 1, else: 0 }
}
}
}
But I just could not figure out entries with the status value equaling 0. Now I feel it is a problem with the abc(’$qty’) parameter passing, but have no clue about how to go about solving it. If abc($qty) reports an error, can somebody help? BTW, I’m just naming an example and am not intending to calculate simple values using complicated functions. My abc function will add many judging statements during actual usage. But now I am more concerned about how to get the field values of each collection and pass them to the abc function on Alibaba Cloud?
` { "_id" : 1, "item" : "abc1", qty: 300 }
{ "_id" : 2, "item" : "abc2", qty: 200 }
{ "_id" : 3, "item" : "xyz1", qty: 250 }
`
Function is as follows:
abd(v){
return v;
}
Now I need to calculate collections with the qty equaling 200 using aggregation pipes, for example:
{$project:{valu e:{
$cond: {
if: { $eq: [ db.eval("abc('$ qty')") , 200 ] }, then: 1, else: 0 }
}
}
}
But I just could not figure out entries with the status value equaling 0. Now I feel it is a problem with the abc(’$qty’) parameter passing, but have no clue about how to go about solving it. If abc($qty) reports an error, can somebody help? BTW, I’m just naming an example and am not intending to calculate simple values using complicated functions. My abc function will add many judging statements during actual usage. But now I am more concerned about how to get the field values of each collection and pass them to the abc function on Alibaba Cloud?
Comment