【问题标题】:Implementing manual linkage/reference in mongoose在猫鼬中实现手动链接/引用
【发布时间】:2014-11-05 02:28:15
【问题描述】:

http://docs.mongodb.org/manual/reference/database-references/#DatabaseReferences-SimpleDirect%2FManualLinking

对于几乎所有要存储两个文档之间关系的情况,请使用手动引用。引用很容易创建,您的应用程序可以根据需要解析引用。

正如 mongodb 参考文档中所指出的,使用手动链接/参考似乎更合理,而不是像这样使用 DBRef:

stories : [{ type: Schema.ObjectId, ref: 'Story' }]

通过 DBref 实现关系看起来非常简单。除此之外,我找不到关于如何在模式中最有效地实现手动引用的可靠资源。建议:

stories : [{ type: Schema.ObjectId}] OR
stories : [{ type: Number] OR
stories : [{ type: String]

手动参考应该如何实现?如果有一个插入的例子也将不胜感激。

【问题讨论】:

    标签: node.js mongodb mongoose document-oriented-db database


    【解决方案1】:

    实现这将取决于您在哪个环境中使用哪个库。

    这是 node.js 中 mongoose 的一个很好的例子: https://mongoosejs.com/docs/populate.html

    【讨论】:

      猜你喜欢
      • 2020-05-22
      • 2019-06-04
      • 2015-05-06
      • 2013-10-22
      • 2016-11-01
      • 1970-01-01
      • 2013-11-24
      • 2014-10-17
      • 2018-09-01
      相关资源
      最近更新 更多