MongoServerError causes application to crash, cannot filter;
Closed this issue · 1 comments
Deleted user commented
Is there an existing issue for this?
- I have searched the existing issues
Current behavior
When using a unique key in the document schema,
@Schema()
export class User {
@Prop({
default: Math.random().toString().substr(2, 8),
})
handle: string;
@Prop({ required: true, unique: true })
display: string;
}
and if you try to create a model with a duplicate key, it ill crash the app
MongoServerError: E11000 duplicate key error collection: vonchat.users index: display_1 dup key: { display: "ulnkose" }
at C:\Users\User\Documents\GitHub\nest\node_modules\mongodb\src\operations\insert.ts:85:25
at C:\Users\User\Documents\GitHub\nest\node_modules\mongodb\src\cmap\connection_pool.ts:518:13
at C:\Users\User\Documents\GitHub\nest\node_modules\mongodb\src\sdam\server.ts:371:13
at handleOperationResult (C:\Users\User\Documents\GitHub\nest\node_modules\mongodb\src\sdam\server.ts:456:14)
at Connection.onMessage (C:\Users\User\Documents\GitHub\nest\node_modules\mongodb\src\cmap\connection.ts:450:5)
at MessageStream.<anonymous> (C:\Users\User\Documents\GitHub\nest\node_modules\mongodb\src\cmap\connection.ts:256:56)
at MessageStream.emit (node:events:527:28)
at processIncomingData (C:\Users\User\Documents\GitHub\nest\node_modules\mongodb\src\cmap\message_stream.ts:193:14)
at MessageStream._write (C:\Users\User\Documents\GitHub\nest\node_modules\mongodb\src\cmap\message_stream.ts:70:5)
at writeOrBuffer (node:internal/streams/writable:389:12)
Minimum reproduction code
https://gist.github.com/ulnk/bf3042eb8bffbc65f396b9e1f3a07ed7
Steps to reproduce
see gist above
Expected behavior
should error and crash nest app
Package version
9.2.0
mongoose version
6.6.5
NestJS version
No response
Node.js version
9.0.0
In which operating systems have you tested?
- macOS
- Windows
- Linux
Other
No response
kamilmysliwiec commented
Please, use our Discord channel (support) for such questions. We are using GitHub to track bugs, feature requests, and potential improvements.