423,335 Members | 1,156 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 423,335 IT Pros & Developers. It's quick & easy.

I am facing some problems in passing field values into function parameters.

P: 22
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:{value:{
$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?
Apr 19 '18 #1
Share this Question
Share on Google+
1 Reply


P: 51

Apr 20 '18 #2

Post your reply

Sign in to post your reply or Sign up for a free account.