Open sweetpalma opened 5 years ago
I have a following model (defined using @tsed/mongoose:
@Model() @MongoosePlugin(UniqueValidator) export class Phone { @Unique() @Required() @Property() serial!: string; }
When I try to find and update it with the following code - validation works:
const car = await this.model.findOneAndUpdate(filter, props, {new: true, context: 'query', runValidators: true});
But when I try to overwrite it - it throws me validation error regarding unique constraint:
const car = await this.model.findOneAndUpdate(filter, props, {new: true, overwrite: true, context: 'query', runValidators: true});
Am I missing something? Or is that really a bug? I am using version 2.0.3.
2.0.3
It's probably a bug. My bet is that the document gets flagged as "new" internally so we need to explicitly look for overwrite.
overwrite
I have a following model (defined using @tsed/mongoose:
When I try to find and update it with the following code - validation works:
But when I try to overwrite it - it throws me validation error regarding unique constraint:
Am I missing something? Or is that really a bug? I am using version
2.0.3
.