如何使用Node.js Mongoose删除文档?

编程入门 行业动态 更新时间:2024-10-22 07:42:28
本文介绍了如何使用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删除文档?

本文发布于:2023-11-22 19:22:13,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1618694.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何使用   文档   js   Node   Mongoose

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!