【问题标题】:What is the correct way to implement a table in Mongo object(document)在 Mongo 对象(文档)中实现表的正确方法是什么
【发布时间】:2020-02-16 18:53:57
【问题描述】:

我对 NoSQL 数据库有点陌生,我想实现以下类型的对象。我使用 MongoDB 和 Mongoose 作为 ODM。

Field 1
Field 2
Table 1, where each row is:
    Column 1
    Column 2
    Column 3

在 SQL DB 中,表将是一个单独的表,第一列是主对象的键。

在 Mongo 中,我可以看到两种方法。一种是制作以下架构:

{
    Field1: Type,
    Field2: Type,
    Table1: [{
        Column1: Type,
        Column2: Type,
        Column3: Type
        }]
}

另外一种是单独创建一个集合“TableRow”并引用它,像这样:

{
    Field1: Type,
    Field2: Type,
    Table1: [{
        Type: ObjectId,
        Ref: "TableRow"
        }]
}

哪一个更好?或者有没有更好的方法我完全错过了?

【问题讨论】:

    标签: mongodb mongoose


    【解决方案1】:

    请使用以下代码

       {
        Field1: Type,
        Field2: Type,
        Table1: [{
        Column1: Type,
        Column2: Type,
        Column3: Type
        }]
       }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-06
      • 2018-08-12
      • 1970-01-01
      • 2020-01-03
      • 2010-11-26
      相关资源
      最近更新 更多