0

I want to get an output for the code

app.get('/_browse', function(req, res){

    var filter = {};
    var type = req.query["type"] || '';
    var nodeValue =  (req.query["nodeValue"]) ? req.query["nodeValue"] : "";
    var nodeApi =  (req.query["nodeApi"]) ? req.query["nodeApi"] : "";
    var node =  (req.query["node"]) ? req.query["node"] : "";
    var callback = req.query["callback"] || '';
    /*var mapobject = {
        kingdom : "phylum",
        phylum : "class",
        class : "order",
        order : "family",
        family : "genus",
        genus : "specificEpithet",

    };*/
    var text = {
            text: nodeValue,
            specimenCount: 'count',
            nodeApi: nodeApi,
            nodeValue: nodeValue,
                }

    var mapobject = {

        phylum : "family",
        family : "genus",
        genus : "specificEpithet",

    };
    var type = mapobject[nodeApi];  
    var nvalue = {};
    if(nodeValue != ''&& nodeApi != '') {
     nvalue[nodeApi] = nodeValue;
    }
    var typeValue = "$"+ type;

collection.aggregate(

        { $match : nvalue},
        { $group : {
            _id : typeValue,
            count : { $sum : 1 },
        }},
        {$sort: {_id: 1}},
    function(err, results) {
        /*results[0]['text'] = text;
        console.log("text values",results[0]['text']);*/
            /*var text = {
            text: "Aceraceae ",
            specimenCount: 'count',
            nodeApi: "Family",
            nodeValue: "Aceraceae",
                }
            results['text'] = text;
            console.log("text values",results.text);
            */  
        (var i in results){
            if(results = text){
                results.text =  nodeValue;
                results.specimenCount = 'count';
                results.nodeApi = nodeApi;
                results.nodeValue = nodeValue;
            console.log("results",results.text);
            }
        res.writeHead(200, {'Content-Type': 'application/json'});
        if (callback != '') {
            res.end(callback + '(' + JSON.stringify({success: true, rows: results}) + ')');

        } else {
                res.end(JSON.stringify({success: true, rows: results}));


            }

    });

}); 

like...

    results: [{
       text: "Acanthaceae (300)",
       specimenCount: "300",
       nodeApi: "Family",
       nodeValue: "Acanthaceae",
       filter: {
           StateProvince: "Louisiana",
           Taxonomy: "",
           Phylum: "dicot"
       }
   },

I did my coding like this way but it is not giving the output. It need to process the results to make this output. Please help me to get the output.

1 Answer 1

1

If you want to print results like above you can do :

  1. console.log("Result: %j", results);
  2. console.log(require('util').inspect(results, false, null));
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.