C
C
CJ_media2021-03-22 15:09:06
MongoDB
CJ_media, 2021-03-22 15:09:06

How to display custom field by _id from MongoDB in React?

There is an application on the MERN stack. It describes such a model for MongoDB

const Master = new Schema({
    master_name: { type: String, required: true },
    rating: { type: Number, default: 0},
    city: { type: ObjectId, ref: 'City' }
});


I need to display in React, the city (city_name) in which the master works, but when accessing the city field from the Master model, the ObjectId of the corresponding city is logically displayed.

Model for City:
const City = new Schema({
    city_name: { type: String, required: true, unique: true }
});


Please help me understand the issue.

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