a Reference Relationship in mongoDB, assuming between a user and their comments, I would have to do something like
let userSchema = new Schema({
_id: Number,
name: String,
comment: {
type: mongoose.Schema.Types.ObjectId,
ref: 'Comment'
},
Whereby Comment is already a `model`ed schema.
Now if I want to save a new user along with the comment, how would I do that?
let user = new userSchema({ name: "Myname ", comment: "id of Comment" )} user.save();
Обсуждают сегодня