Node.js 使用mongoose在$push之后获取对象的ID
我当前正在使用以下命令更新嵌入文档:Node.js 使用mongoose在$push之后获取对象的ID,node.js,mongodb,mongoose,Node.js,Mongodb,Mongoose,我当前正在使用以下命令更新嵌入文档: User.findByIdAndUpdate(user,{$push:{"position": {title:req.body.title,location:req.body.location,start:req.body.start,term:req.body.term,description:req.body.description}}}).exec(function (err, result) { if (result){ co
User.findByIdAndUpdate(user,{$push:{"position":
{title:req.body.title,location:req.body.location,start:req.body.start,term:req.body.term,description:req.body.description}}}).exec(function (err, result)
{
if (result){
console.log(result.position);
}
else{
}
该对象正在成功地插入到用户集合的“positions”部分,但是,在推送该对象时,我需要该对象的_id。
当我记录结果数组时,我得到数组中的所有位置,除了我刚才输入的位置,但是它在数据库中。
有没有办法拿到身份证 可能的重复可能的重复