Lets say that I have this user schema that has a inventory with multiple slots. How could I nest those slotsimg and slottext fields inside the inventory field?
For example like this:
const UserSchema = new mongoose.Schema({
Inventory: {
slot1img: {
type: String,
},
slot1text: {
type: String,
},
slot2img: {
type: String,
},
slot2text: {
type: String,
},
slot3img: {
type: String,
},
},
});
However if I try it like this it wont show up at all in the database, so how do i do this?
I have found a solution: https://docs.mongodb.com/manual/tutorial/model-embedded-one-to-many-relationships-between-documents/#embedded-document-pattern . If anyone else runs in to this problem use the link:)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.