【问题标题】:Mongodb Schema using mongooseMongodb Schema 使用 mongoose
【发布时间】:2018-12-30 00:33:07
【问题描述】:

这是我的用户架构:

const userSchema = new Schema({

email: String,
username: String,
password: String,
secretToken: String,
active: Boolean,
type: String

},{

timestamps: { // this will give us the detail when the account is created

    createdAt: 'createdAt',
    updatedAt: 'updatedAt'
}

});

这是我的要求架构:

const requirementsSchema = new Schema({

name: String,
age: String,
class: String,
subject: String,
email: String

},{

timestamps: { // this will give us the detail when the requiremnt is created

    createdAt: 'createdAt',
    updatedAt: 'updatedAt'
}

});

如何将用户架构中的 id 作为辅助键带入需求架构?

【问题讨论】:

    标签: mongodb mongoose schema primary-key


    【解决方案1】:

    我认为 mongodb 不适合关系。如果您的数据库增长,我可能会导致非常糟糕的做法。但是您可以尝试 https://docs.mongodb.com/manual/reference/database-references/#DatabaseReferences-DBRef 获取数据库引用。

    MongoDB中没有主键外键的概念。在 mongodb 中也不鼓励规范化。

    【讨论】:

    • 我知道没有主键外键概念,但我想显示这两个模式之间的关系,我该怎么做?
    猜你喜欢
    • 2014-12-02
    • 2018-03-15
    • 1970-01-01
    • 2020-06-17
    • 2020-10-20
    • 2021-05-06
    • 2021-04-09
    • 2020-09-15
    • 2013-03-11
    相关资源
    最近更新 更多