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

Model.deleteMany does not respect the writeConcern options #867

Closed
thongxuan opened this issue Jul 10, 2023 · 3 comments
Closed

Model.deleteMany does not respect the writeConcern options #867

thongxuan opened this issue Jul 10, 2023 · 3 comments
Labels
bug Something isn't working not a typegoose issue This is not a typegoose issue / This pr addresses something that shouldnt be in typegoose

Comments

@thongxuan
Copy link

Versions

  • System: macos
  • NodeJS: 18.16.0
  • Typescript: 5.0.4
  • Compiler / Transpiler: ts-node
  • Typegoose(NPM): 11.0.0
  • Typegoose(GIT): commithash
  • mongoose: 7.0.3
  • mongodb: 5.2.0
  • grahpql / type-graphql: 15.5.0 / 1.1.1

What is the Problem?

Model.deleteMany does not respect the writeConcern options

Code Example

I have a LogModel defined using

import { getModelForClass, modelOptions } from '@typegoose/typegoose';
@modelOptions({ schemaOptions: { writeConcern: { w: 0 } } })
export class Log {...}

export const LogModel = getModelForClass(Log);

the write concern here is to speedup the log write requests.

Now I would like to remove the logs inside a transaction with other models, and the error is:
Cannot have explicit session with unacknowledged writes

await withTransaction(async (session) => {
    ...other removal
    await LogModel.deleteMany({ user: user._id }, { session });
    ...other removal
});

I tried supply explicit write concern into the deleteMany query to override the setting in model, but same error occurs.

await withTransaction(async (session) => {
    ...other removal
    await LogModel.deleteMany({ user: user._id }, { session, writeConcern: { w: 'majority', j: true } });
    ...other removal
});

Do you know why it happens?

no


@thongxuan thongxuan added the bug Something isn't working label Jul 10, 2023
@hasezoey
Copy link
Member

maybe check the mongoose log via mongoose.set('debug', true) before running your transaction

also if this really is not running properly, then this is a mongoose problem, not a typegoose one

@hasezoey hasezoey added the not a typegoose issue This is not a typegoose issue / This pr addresses something that shouldnt be in typegoose label Jul 10, 2023
@thongxuan
Copy link
Author

Mongoose team confirmed and fixed this bug. Thanks.

@hasezoey
Copy link
Member

hasezoey commented Jul 21, 2023

for reference, i guess Automattic/mongoose#13592 is the one that was opened for this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working not a typegoose issue This is not a typegoose issue / This pr addresses something that shouldnt be in typegoose
Projects
None yet
Development

No branches or pull requests

2 participants