Answer the question
In order to leave comments, you need to log in
How to save an instance of a linked model in a different way?
let schemaGroup = new Schema({
name: { type: String, required: true },
comment: { type: String, default: '' }
})
model('G', schemaGroup)
let schemaAbonents = new Schema({
firstName: { type: String, required: true },
group: { type: Types.ObjectId, required: true }
})
module.exports = model('A', schemaAbonents)
let idGr = await G.findOne({name: 'value'})
let ab = new A({firstName: 'Alex', group: idGr}) // <-- Вот это место вопроса
ab.save()
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question