【问题标题】:Mongoose schema method not working after select paramter选择参数后猫鼬模式方法不起作用
【发布时间】:2016-05-02 11:11:47
【问题描述】:

我有一个猫鼬模型,它带有一个检查字段并动态返回值的方法,并在 HTML 模板中调用。

在清理路线以仅选择页面上需要的字段时,这给了我一个问题。

在包含 Model.find({}, 'select parameter', cb... 中的 select 参数后,此架构方法开始失败,尽管在 select 参数中包含此架构方法检查的属性。

这是怎么回事,有办法解决吗?

架构方法在thingSchema.methods: { ... ...内部定义

并寻找this.thing.length

包含在选择参数'thing, otherThing, thingyThing, thingestThing'

并在像thing.getThing()这样的html模板中调用,这将抛出错误找不到未定义的道具长度。

【问题讨论】:

    标签: node.js mongoose mongoose-schema


    【解决方案1】:

    原来选择参数的字符串类型有问题。

    改用对象类型:{thing:1,otherThing:1,things:1}

    【讨论】:

      猜你喜欢
      • 2016-12-27
      • 2014-05-01
      • 2015-05-09
      • 1970-01-01
      • 1970-01-01
      • 2016-05-04
      • 1970-01-01
      • 2018-10-28
      • 2021-04-03
      相关资源
      最近更新 更多