Populate nesting usage of mongodb

has the following two Model

(1) user Model

var usersSchema = new Schema({
    f_id: {
        unique: true,
        type: String
    },
    f_name: String
})

(2) record Model

var batchMainSchema = new Schema({
        f_id: {
            unique: true,
            type: String
        },
        f_user_log: [{
            f_option: String,
            f_time: Date,
            f_user_model: { type: Schema.Types.ObjectId, ref: "users" },
        }]
    })

user action records need to be saved in the f_user_log field in the record Model

can you get the value of f_user_model when querying record data

?

the writing method in the following figure can not get the desired user information

clipboard.png

do you have any corresponding solutions? thank you!

Mar.10,2021

populate cannot, use aggregate .


.populate ({path: 'fame username log. Fancy username model'})

Menu