【发布时间】:2017-12-30 12:03:46
【问题描述】:
假设我想要一个数据模式:每个用户都可以拥有许多笔记本电脑,有些笔记本电脑可用,有些则没有。 我希望我能得到一些类似的架构,
User
| userId: 1
| laptops:
| laptopId: 1 available: true //default
| laptopId: 2 available: true
如何定义这样的架构? 以下不正确:
const User = new mongoose.Schema({
userId: {
type: String,
index: { unique: true }
},
laptops: {
laptopId: String,
available: Boolean
}
});
如何在 node.js 中的 Mongoose 中定义这个?
【问题讨论】:
标签: node.js mongodb mongoose-schema