How to set objectId to userId when mongoose creates a user

const UserSchema = new Schema({
    userId:Schema.Types.ObjectId,
    username: String,
    mobile: String,
    password: String,
    //
    remarks: String,
    createAt: {type: Date, default: Date.now},
    updateAt: {type: Date, default: Date.now},
    //
    userType: String
})

this is the user schema, I defined. How do I set the userId value to the default objectId, when I want to default inch data?
when I query, I need to query the data according to the user id or objectId, and how to get the objectId?

the following is the code for me to store the data:

let password = md5(ctx.request.body.password)
            let UserModel = new User({
                username: ctx.request.body.username,
                mobile: ctx.request.body.mobile,
                password: password,
                remarks: ctx.request.body.remarks
            })
            UserModel.save(function (err) {
                if (err) console.log(err)
            })
Mar.08,2021

1. Why can't you use the default id
2. If you customize id, the default id will also automatically generate
3. To use a custom id query, just use a custom field name. Of course, the default id is also a

that you can continue to use.
Menu