使用MongoDB我应该在用户模式中嵌套与用户相关的所有内容吗?

时间:2013-12-02 02:52:16

标签: node.js mongodb mongoose nosql

下面举一个例子,让我觉得这个问题更容易。我应该这样做,还是表现更好?我可能也希望稍后再添加一些内容。

user: new schema({
    key: type.unique.string // uuid
  , nickname: type.string
  , username: type.unique.string
  , password: type.string
  , email: type.optional.string
  , role: { type: String, required: true, default: 'user', enum: ['user', 'administrator'] }
  , active: type.bool
  , created: type.timestamp
  , last: type.timestamp
  , products: { type: [{ product: type.string, cost: type.number, when: type.timestamp, where: type.string }] }
  , sessions: { type: [{ who: type.unique.string, when: type.timestamp, where: type.number, what: type.string }] }
})

1 个答案:

答案 0 :(得分:2)

对此没有正确的答案。这取决于你知道的很多因素。

一些文档可以帮助您做出决定:

http://docs.mongodb.org/manual/core/data-model-design/