我想得到代码的输出
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}));
}
});
});
喜欢...
results: [{
text: "Acanthaceae (300)",
specimenCount: "300",
nodeApi: "Family",
nodeValue: "Acanthaceae",
filter: {
StateProvince: "Louisiana",
Taxonomy: "",
Phylum: "dicot"
}
},
我以这种方式进行了编码,但没有给出输出。它需要处理结果以产生此输出。请帮助我获得输出。