本文介绍了如何使用 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 删除文档?
发布评论