【发布时间】:2018-03-11 17:39:59
【问题描述】:
我有一个 MongoDB 集合 users,我想在其中存储带有动态键的字典。我希望 users 在 MongoDB 中看起来像这样:
{
"_id": {
"$oid": "5a9f5b3400e2f61a0c5f449b"
},
"profile": {
"votes": {
dynamicKey1Here: {
constantKey: 'value',
constantKey2: 'value2'
},
dynamicKey2Here: {
constantKey: 'value',
constantKey2: 'value2'
},
// more dynamic keys here...
}
}
但我不知道如何定义我的架构。到目前为止,我有:
const userSchema = new Schema({
profile: {
votes: {DynamicKeyEntry}
}
});
那么我将如何定义DynamicKeyEntry 的架构?
const DynamicKeyEntry = new Schema(
// HOW DO I DEFINE DYNAMIC KEYS?
);
【问题讨论】:
标签: mongodb dictionary dynamic database-schema mongoose-schema