Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MongoDB deleteMany seems to send 2 identical read queries first before triggering the actual delete #15085

Closed
janpio opened this issue Aug 30, 2022 · 1 comment · Fixed by prisma/prisma-engines#4249
Labels
bug/2-confirmed Bug has been reproduced and confirmed. kind/bug A reported bug. team/client Issue for team Client. topic: mongodb topic: performance/queries
Milestone

Comments

@janpio
Copy link
Member

janpio commented Aug 30, 2022

As seen in #15084, a MongoDB deleteMany seems to send 2 identical read queries first before triggering the actual delete. One of those is probably not necessary:

$ ts-node ./script.ts
deleteMany
prisma:query db.User.aggregate([ { $match: { $expr: { }, }, }, { $project: { _id: 1, }, }, ])
prisma:query db.User.aggregate([ { $match: { $expr: { }, }, }, { $project: { _id: 1, }, }, ])
prisma:query db.User.deleteMany({ _id: { $in: [ ObjectId("6d795f757365725f69643030"), ], }, })

4.3.0-dev.84

@janpio janpio added bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. kind/bug A reported bug. team/client Issue for team Client. topic: mongodb topic: performance/queries labels Aug 30, 2022
@Jolg42
Copy link
Member

Jolg42 commented Aug 30, 2022

Can reproduce the 2 identical queries

deleteMany
prisma:query db.User.aggregate([ { $match: { $expr: { }, }, }, { $project: { _id: 1, }, }, ])
prisma:query db.User.aggregate([ { $match: { $expr: { }, }, }, { $project: { _id: 1, }, }, ])
prisma:query db.User.deleteMany({ _id: { $in: [ ObjectId("6d795f757365725f69643030"), ], }, })
...

Note: I only see db.User.deleteMany line on a second run

@Jolg42 Jolg42 added bug/2-confirmed Bug has been reproduced and confirmed. and removed bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. labels Aug 30, 2022
@Jolg42 Jolg42 added this to the 5.4.0 milestone Sep 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug/2-confirmed Bug has been reproduced and confirmed. kind/bug A reported bug. team/client Issue for team Client. topic: mongodb topic: performance/queries
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants