Files
payload/packages/db-mongodb/src/deleteMany.ts
Patrik fb72d19d6c fix: graphql query concurrency issues (#6925)
## Description

This is the beta (v3) PR for the v2 PR
[here](https://github.com/payloadcms/payload/pull/6857)

Addresses #6800, #5108

- [x] I have read and understand the
[CONTRIBUTING.md](https://github.com/payloadcms/payload/blob/main/CONTRIBUTING.md)
document in this repository.

## Type of change

- [x] Bug fix (non-breaking change which fixes an issue)

## Checklist:

- [x] I have added tests that prove my fix is effective or that my
feature works
- [x] Existing test suite passes locally with my changes
2024-07-08 15:55:04 +00:00

24 lines
558 B
TypeScript

import type { DeleteMany, PayloadRequest } from 'payload'
import type { MongooseAdapter } from './index.js'
import { withSession } from './withSession.js'
export const deleteMany: DeleteMany = async function deleteMany(
this: MongooseAdapter,
{ collection, req = {} as PayloadRequest, where },
) {
const Model = this.collections[collection]
const options = {
...(await withSession(this, req)),
lean: true,
}
const query = await Model.buildQuery({
payload: this.payload,
where,
})
await Model.deleteMany(query, options)
}