S
S
soofftt912020-01-04 17:52:03
MongoDB
soofftt91, 2020-01-04 17:52:03

How to create a Mongoose schema with an array and references to it in the same document?

There is a conditional model of the following content:

...
attachments: [{
  _id: true,
  alt: { type: String, default: '' },
  url: { String }
}],
content: [{
  title: String,
  text: String,
  attachments: [
    // тут нужно ссылатся на this.attachments._id
  ]
}]
...

Please tell me how to set up links from "content.attachments" to the "attachments" array and how to do populate() with this approach?

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