Я пытаюсь сбросить текстовое поле в области видимости pre findOneAndUpdate. Те 3 разных способа, которыми я пользовался, не сработали. Как можно удалить какое-то поле в этой области?
const UserSchema: SmartSchema = new SmartSchema({
id: Schema.Types.ObjectId,
userId: { type: Number, required: true },
text: String
});
UserSchema.pre('findOneAndUpdate', function(next: HookNextFunction) {
let query: Query = this as Query;
query
.update(
{},
{ 'text': undefined },
{ strict: false }
)
.exec()
// OR
query
.update(
{},
{ $unset: { 'text': undefined } },
{ strict: false }
)
.exec()
// OR
delete query._update.text;
next();
});