Javascript 抛出消息;TypeError:第一个参数必须是字符串或缓冲区
我正在尝试以下代码:Javascript 抛出消息;TypeError:第一个参数必须是字符串或缓冲区,javascript,node.js,Javascript,Node.js,我正在尝试以下代码: 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,
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);
});
});
});
我尝试了
res.status(200).发送(doc)
而不是res.end(doc)代码>而且效果很好 可能是您遇到了如下问题:[link]()
/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)