'Creating Two Foreign key mongoose inside a controller

Hi I want to implement this snippet of my class diagram using mongoose.

enter image description here

Here is my logic model in detail:

enter image description here

Here is the definition of my Mother model:

const mongoose = require('mongoose')

const motherSchema = mongoose.Schema({
    cniMother: { type: Number, required: true },
    name: { type: String, required: true },
    surname: { type: String, required: true },
    birthDay: { type: Date, required: true },
    birthPlace: { type: String, required: true },
    address: { type: String, required: true },
    phone: { type: Number, required: true },
    occupation: { type: String, required: true },
}); 

module.exports = mongoose.model('Mother', motherSchema);

Here is the definition of my Declared model:

const mongoose = require('mongoose')

const declaredSchema = mongoose.Schema({
    name: { type: String, required: true },
    surname: { type: String, required: true },
    father: {
        type: mongoose.Schema.Types.ObjectId,
        ref: 'Father',
        //required: true,
    },
    mother: {
        type: mongoose.Schema.Types.ObjectId,
        ref: 'Mother',
        //required: true,
    },
    birthDay: { type: Date, required: true },
    birthPlace: { type: String, required: true },
    gender: { type: String, required: true },
    nationality: { type: String, required: true }
}); 

module.exports = mongoose.model('Declared', declaredSchema);

I want to retrieve the name of the father and the mother corresponding to the declared. Can anyone help me please?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source