【问题标题】:What is need of specifying ref here in the below mongoose schema? What if we don't specify it?在下面的 mongoose 模式中指定 ref 需要什么?如果我们不指定呢?
【发布时间】:2021-05-10 00:18:44
【问题描述】:
 eventsAttended: [{ type: Schema.Types.ObjectId, ref: 'Event' }]

【问题讨论】:

  • 文档是怎么说的?

标签: javascript mongodb mongoose mern


【解决方案1】:

Ref 是 mongoose 的一个选项,用于填充给定模式的字段。因此,如果您在“eventsAttended”字段中省略 ref,您只会获得一个 objectID 值,而不会引用任何架构。

这里的文档: https://mongoosejs.com/docs/api.html#schematype_SchemaType-ref

这里的指南: https://mongoosejs.com/docs/populate.html

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-01-04
    • 2013-05-28
    • 2011-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-16
    相关资源
    最近更新 更多