如何使用 Node.js Mongoose 删除文档? [英] How do I remove documents using Node.js Mongoose?
本文介绍了如何使用 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 删除文档?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文