I have this schema to create a user and in this schema I want check some property is modified or not:
I have a code like this:
import mongoose from 'mongoose';
import uniqueString from 'unique-string';
import { BaseSchema } from './BaseSchema';
enum Gender {
Male = 1,
Female = 2,
Trans = 3
}
interface UserAttrs {
firstName: string;
lastName: string;
phoneNumber: string;
password: string;
}
export interface UserDoc extends mongoose.Document {
firstName: string;
lastName: string;
phoneNumber: string;
password: string;
}
interface UserModel extends mongoose.Model<UserDoc> {
build(userAttrs: UserAttrs): UserDoc;
}
const UserSchema = new mongoose.Schema({
firstName: {
type: String,
required: true
},
lastName: {
type: String,
required: true
},
phoneNumber: {
type: String,
required: true
},
password: {
type: String,
required: true
}
})
UserSchema.pre('updateOne', function () {
this.set({ securityStamp: uniqueString() });
});
UserSchema.statics.build = (attrs: UserAttrs) => {
return new UserModel(attrs);
}
const UserModel = mongoose.model<UserDoc, UserModel>("User", UserSchema);
export { UserModel }
I want to check field is modified or not, in this way its not worked for me:
UserSchema.getUpdate().$set.password
but it show me this Error :
getUpdate
is not function .
whats the problem ? how can i sovle this problem ?
question from:
https://stackoverflow.com/questions/65950078/chekc-fild-is-modified-or-not-in-mongoose-and-nodejs 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…