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)
})