close
Skip to content

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

@thongxuan

Description

@thongxuan

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    confirmed-bugWe've confirmed this is a bug in Mongoose and will fix it.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions