本文介绍了如何使用Node.js Mongoose删除文档?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
FBFriendModel.find({
id: 333
}, function (err, docs) {
docs.remove(); //Remove all the documents that match!
});
上面似乎不工作。记录仍然存在。
The above doesn't seem to work. The records are still there.
有人可以修复吗?
推荐答案docs 是一个文档数组。因此它没有 mongooseModel.remove()方法。
docs is an array of documents. so it doesn't have a mongooseModel.remove() method.
您可以迭代和删除每个文档
You can iterate and remove each document in the array separately.
或者 - 因为它看起来像是通过一个(可能)唯一的id查找文档 - 使用 findOne 而不是 find 。
Or - since it looks like you are finding the documents by a (probably) unique id - use findOne instead of find.
更多推荐
如何使用Node.js Mongoose删除文档?
发布评论