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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • TimoHa
    New Member
    • Nov 2017
    • 22

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

    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?
  • IvanH
    New Member
    • Nov 2017
    • 51

    #2

    Comment

    Working...