gpt4 book ai didi

mongoose - Query 和 Model mongoose 的区别

转载 作者:行者123 更新时间:2023-12-04 17:43:17 25 4
gpt4 key购买 nike

这些天我试图了解更多关于 Mongoose 的知识,以便在我的项目中实现它,在浏览文档时,我看到了 ModelQuery ,两者都有很多共同点,我的问题是它们之间有什么区别,例如
Model.findOne()对比 Query.prototype.findOne() ,并提前致谢。

最佳答案

模型.findOne() 是使用 findOne() 查询从数据库中查找单个文档的实际方法

Query.prototype.findOne() 表示 findOne Query 的原型(prototype)

as per documentation : 你可以通过你的过滤器、投影、选项 对象和 回调功能到您的查询

例子 :

 Kitten.where({ color: 'white' }).findOne(function (err, kitten) {
if (err) return handleError(err);
if (kitten) {
// doc may be null if no document matched
}
});

Mongoose 已经展示了所有 Query 的原型(prototype)您可以使用您的 Model ,这意味着您可以在查找文档时传递给您的 Query 。

关于mongoose - Query 和 Model mongoose 的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53437031/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com