-
Notifications
You must be signed in to change notification settings - Fork 2.1k
MongoDB slow delete with onDelete: SetNull #19169
Copy link
Copy link
Closed
Labels
bug/1-unconfirmedBug should have enough information for reproduction, but confirmation has not happened yet.Bug should have enough information for reproduction, but confirmation has not happened yet.kind/bugA reported bug.A reported bug.topic: indexestopic: mongodbtopic: performance/queriestopic: relationModeformerly `referentialIntegrity`formerly `referentialIntegrity`topic: relations
Milestone
Description
Bug description
When having a schema with a 1:n relation where you delete the left side. It takes on big collections (>1.Mio documents) long time to delete the document (>1 minute).
How to reproduce
You generate a bad query to check the depending documents
{"params":"[]","duration":12735,"query":"db.Broadcast.aggregate([ { $match: { $expr: { $and: [ { }, { $and: [ { $in: [ \"$productionId\", [ { $literal: ObjectId(\"5f913feb235d8600075e1797\"), }, ], ], }, { $ne: [ \"$productionId\", \"$$REMOVE\", ], }, ], }, ], }, }, }, { $project: { _id: 1, productionId: 1, }, }, ])"}
There need to be a query which can use the normal index in mongodb like
db.Broadcast.find({productionId: ObjectId(\"5f913feb235d8600075e1797\")})
Expected behavior
No response
Prisma information
model Broadcast {
id String @id @default(auto()) @map("_id") @db.ObjectId
productionId String? @db.ObjectId
production Production? @relation("ProductionBroadcasts", fields: [productionId], references: [id], onDelete: SetNull, onUpdate: Cascade)
}
model Production {
id String @id @default(auto()) @map("_id") @db.ObjectId
}prisma.production.delete({where: {id: "...."}})Environment & setup
Node: 19.7.0
Mongo: 6.0.5
Prisma Version
PrismaClient: 4.14.0
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bug/1-unconfirmedBug should have enough information for reproduction, but confirmation has not happened yet.Bug should have enough information for reproduction, but confirmation has not happened yet.kind/bugA reported bug.A reported bug.topic: indexestopic: mongodbtopic: performance/queriestopic: relationModeformerly `referentialIntegrity`formerly `referentialIntegrity`topic: relations