【问题标题】:Mongoose - Multiple Schemas vs Objects within One Schema to store connected documents [duplicate]Mongoose - 一个模式中的多个模式与对象以存储连接的文档[重复]
【发布时间】:2016-01-08 22:27:17
【问题描述】:

我的 Mongo 数据库中有 MemberSchemaFacebookSchema

如果会员注册到我的网站,会员信息将存储在MemberSchema

如果注册会员想要连接他的 facebook 帐户,他需要验证他的 facebook 帐户到我的网站。然后,他所有的脸书账号信息都会存储在FacebookSchema

这是我当前的 Schema 配置:

var Member = new Schema({
    email: String,
    password: String,
    memberType: { type: String , default: 'webaccount' },
    facebookAccount: { type: Schema.Types.ObjectId, ref: 'facebook_accounts' }
});

var FacebookAccount = new Schema({
    fbId: String,
    email: { type : String , lowercase : true},
    name: String,
    memberType: { type: String , default: 'facebook' }
});

这两个模式通过MemberSchemafacebookAcount 属性连接。

但我已经考虑了另一种存储这些数据的方式,通过 Object 在 Schema 中键入。

var Member = mongoose.Schema({

    webaccount            : {
        email        : String,
        password     : String,
    },
    facebook         : {
        id           : String,
        token        : String,
        email        : String,
        name         : String
    }
});

您认为,在这种情况下,哪种方式可能更适合应用?

每种方法的优缺点是什么?

提前致谢。

【问题讨论】:

    标签: node.js facebook mongodb mongoose schema


    【解决方案1】:

    根据我的说法,您应该将 facebook 数据嵌套到成员集合中。 MongoDB 不适合执行连接。

    【讨论】:

      猜你喜欢
      • 2012-01-28
      • 2015-10-10
      • 2014-11-29
      • 1970-01-01
      • 2012-10-27
      • 2018-10-22
      • 1970-01-01
      • 2015-06-29
      • 2018-08-25
      相关资源
      最近更新 更多