根据mongodb数据记录里面的_id字段删除相应的docs,通过下面代码进行删除时,并不能删除成功
代码如下:
var ObjectId = require('mongodb').ObjectId;
db.collection('infochanges').remove({"_id":{"_id":ObjectId(idvalue)}).then(function(){})
报错如下:
TypeError:Cannot convert undefined or null to object
解决方法:
使用findAndRemove,代码如下:
db.collection('infochanges').findAndRemove({"_id":ObjectId(index)}).then(function(){})
通过_id删除docs要用findAndRemove,remove不起作用