V
V
Vladimir Mirka2017-11-02 11:12:54
MongoDB
Vladimir Mirka, 2017-11-02 11:12:54

Mongoose how to get property of related object by its id?

There is a model GenreModel which contains two properties:
_id(created automatically) and genre_namestring type.
There is a Games model that contains:

game_name: { type: String, required: true, index: true},
game_genre: {type: mongoose.Schema.Types.ObjectId, ref: 'GenreModel', required: true }

The question is how to make game_genre not only have a GenreModel identifier, but also its genre_name property? That is, there must be an object with an identifier and its name.
UPD: Solution to this issue: mongoosejs.com/docs/2.7.x/docs/populate.html

Answer the question

In order to leave comments, you need to log in

2 answer(s)
N
Negwereth, 2017-11-02
@flexaccess

populate

E
Eugene, 2017-11-02
@EShein

Read about get and set, it should help you.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question