Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/42.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 有条件地将_id字段添加到mongoose模型_Node.js_Mongodb_Mongoose - Fatal编程技术网

Node.js 有条件地将_id字段添加到mongoose模型

Node.js 有条件地将_id字段添加到mongoose模型,node.js,mongodb,mongoose,Node.js,Mongodb,Mongoose,我有以下代码: var concert = new models.concert({ name: request.body.name, date: request.body.date, city: request.body.city, location: request.body.location, programme: request.body.programme }); console.log("<< Concert to attempt

我有以下代码:

var concert = new models.concert({
    name: request.body.name,
    date: request.body.date,
    city: request.body.city,
    location: request.body.location,
    programme: request.body.programme
});
console.log("<< Concert to attempt save on: " + concert);
if (request.body._id) {
    console.log("Received _id field from body: " + request.body._id);
    concert._id = ObjectId(request.body._id + '');
}
var concert=new models.concert({
名称:request.body.name,
日期:request.body.date,
城市:request.body.city,
位置:request.body.location,
节目:request.body.program
});
控制台日志(“
<< Concert to attempt save on: 
{ 
    _id: 572312a289a4d8d810eed717,
    programme: 'to be announced',
    location: 'J.Nepomuk-Kapelle',
    city: 'Vienna, Austria32',
    date: 1464382800,
    name: 'Chamber Music Concert' 
}