我正在尝试这段代码:
app.get('/caminhosRelevantes',function(req,res){
console.log(req.protocol+":/"+req.get('host'));
var collection = "caminhos";
var ObjectId = require('mongodb').ObjectID;
collectionDriver.getCollection(collection, function(error, the_collection) {
if (error) {
res.end("<h1>Eerro</h1>");
}
else
the_collection.aggregate([
{ $match: { id_usuario: "54bef57a14b88ad70a8ab74e" } },
{ $group: { _id: { rua: "$rua", data: "$data" } } },
{ $group: { _id: "$_id.rua", data: { $push: "$_id.data" }, count: { $sum: 1 } } },
{ $match: { count: { $gt: 5 } } }
], function(error,doc) { //C
if (error) res.end(error);
else res.end(doc);
});
});
});
但我收到以下错误:
/server/node_modules/mongodb/lib/mongodb/connection/base.js:242
throw message;
^
TypeError: first argument must be a string or Buffer
at ServerResponse.OutgoingMessage.write (http.js:851:11)
at ServerResponse.OutgoingMessage.end (http.js:985:16)
答案 0 :(得分:1)
我已尝试res.status(200).send(doc)
而不是res.end(doc);
,而且效果很好!