简体   繁体   中英

How to create nested fields in a schema?

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?

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM