D
D
d1zz72021-05-29 14:04:22
Mongoose
d1zz7, 2021-05-29 14:04:22

How to get data from linked documents?

Such a thing.
I return the list of salons

const salon = await Salon.find({$text: {$search: searchText, $caseSensitive: false}})

The interior model has a type that is taken from another collection:
type: [{ type: Schema.Types.ObjectId, ref: 'salon_types' }],


Can you tell me how to return to the front also the type of cabin, along with the cabin. Well, so that they are together, otherwise it is ObjectID that is stored in the type field. You can search for a type by it: Here's how it can be correctly implemented
salonType.findById() // типа так

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Yarkov, 2021-05-29
@d1zz7

https://mongoosejs.com/docs/populate.html#population
https://www.npmjs.com/package/mongoose-autopopulate

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question