I have a Model called User for the users schema and a Model called Project for the projects Schema.
const userSchema = new mongoose.Schema(
{
name: { type: String, required: true, unique: true },
email: {
type: String,
unique: true,
required: true,
},
password: { type: String, required: true },
},
{ timestamps: true }
);
const projectSchema = new mongoose.Schema(
{
name: {
type: String,
},
client: {
type: String,
},
developers: [
{type: mongoose.Schema.ObjectId, ref: 'User'}
],
description: { type: String },
},
{ timestamps: true }
);
Developers is going to be an array of ObjectIds so as to get the info from User Schema.
This is how it would look like in the database:
What i am trying to do now is to access the name of the user through the developers array. If i do somethink like:
console.log(project.developers.map((developer) => developer));
i only get the id of the user/developer as a string and not the nested info:
But if i console.log developer.name i get undefined.
Is there a way to access the name of the developer through ObjectId?