1

In frontend we have data like

imagine A is having two child B and C and B having 2 child D and E similarly C is having F and G

how we can store in db like [{A , child[B,C]},{B , child[D,E]} , {C , child[F ,G]}] this structure here we have to use ObjectID for relation

any suggestion are welcome

i was trying to create objectID from reactJS for this structure am i on right Way ? if yes will any hexastring accept mongoDB

1 Answers1

0

You can store array of objects with the schema as

 new Schema({
    email: { type: mongoose.Types.ObjectId, ref: "User" },
   `enter code here` Book: [{ bookName: String }]
}, { timestamps: true })

and save documents as

Book01 = new bookModel({
   email: mail._id,
   Book: [{ file }]
})
await Book01.save();
DerKorb
  • 672
  • 4
  • 10