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 writeConcern settings in options #13592

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

Model.deleteMany does not respect writeConcern settings in options #13592

thongxuan opened this issue Jul 10, 2023 · 3 comments
Labels
confirmed-bug We've confirmed this is a bug in Mongoose and will fix it.
Milestone

Comments

@thongxuan
Copy link

thongxuan commented Jul 10, 2023

Prerequisites

  • I have written a descriptive issue title

Mongoose version

7.0.3

Node.js version

18.16.0

MongoDB version

5.2.0

Operating system

macOS

Operating system version (i.e. 20.04, 11.3, 10)

No response

Issue

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
});

so I think the deleteMany is not respecting the overriding options.

@thongxuan thongxuan added help This issue can likely be resolved in GitHub issues. No bug fixes, features, or docs necessary help wanted labels Jul 10, 2023
@vkarpov15 vkarpov15 added this to the 7.3.3 milestone Jul 10, 2023
@vkarpov15 vkarpov15 added needs repro script Maybe a bug, but no repro script. The issue reporter should create a script that demos the issue and removed help This issue can likely be resolved in GitHub issues. No bug fixes, features, or docs necessary help wanted labels Jul 10, 2023
@vkarpov15 vkarpov15 modified the milestones: 7.3.3, 7.4.1 Jul 10, 2023
@thongxuan
Copy link
Author

thongxuan commented Jul 11, 2023

@IslandRhythms
Copy link
Collaborator

MongooseServerSelectionError: Could not connect to any servers in your MongoDB Atlas cluster. One common reason is that you're trying to access the database from an IP that isn't whitelisted. Make sure your current IP address is on your Atlas cluster's IP whitelist

@IslandRhythms IslandRhythms added needs clarification This issue doesn't have enough information to be actionable. Close after 14 days of inactivity and removed needs repro script Maybe a bug, but no repro script. The issue reporter should create a script that demos the issue labels Jul 11, 2023
@thongxuan
Copy link
Author

thongxuan commented Jul 12, 2023

@IslandRhythms this is not related to the reported issue.
You guys wanted a reproduce repo, and I provided it. You should replace the DB connection string in the repo by yours.

Edit: I have open public access to my test database, please check again.

@IslandRhythms IslandRhythms added confirmed-bug We've confirmed this is a bug in Mongoose and will fix it. and removed needs clarification This issue doesn't have enough information to be actionable. Close after 14 days of inactivity labels Jul 12, 2023
vkarpov15 added a commit that referenced this issue Jul 20, 2023
fix: prevent overwriting user defined writeConcern
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
confirmed-bug We've confirmed this is a bug in Mongoose and will fix it.
Projects
None yet
Development

No branches or pull requests

3 participants