M
M
MOV_UA2020-11-29 16:30:52
Mongoose
MOV_UA, 2020-11-29 16:30:52

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 question

Ask a Question

731 491 924 answers to any question