gpt4 book ai didi

node.js - Mongoose:一系列自定义实例

转载 作者:太空宇宙 更新时间:2023-11-04 01:13:26 25 4
gpt4 key购买 nike

根据文档我可以做这样的事情:

var animalSchema = new Schema({ name: String, type: String });

animalSchema.methods.findSimilarTypes = function (cb) {
return this.model('Animal').find({ type: this.type }, cb);
}

假设我还有另一个功能:

animalSchema.methods.owner 过滤 animalScheme.owner 是否为 xyz,因此它将搜索查询修改为 {...,owner: xyz}

是否可以顺序使用实例?我怎样才能做到这一点?

var animalSchema.findSimilarTypes().owner("xyz") ?

有什么提示吗?

最佳答案

我相信这不会立即起作用,因为原始函数 findSimilarTypes 不会返回架构对象。

我猜您正在尝试对 jQuery 的工作方式做一些事情。

关于node.js - Mongoose:一系列自定义实例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13841169/

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