I'm facing an issue with typing Mongo collection method responses in my app. Specifically, I am having trouble finding a way to type the response of the deleteMany
method. The documented response should look like this:
{ "acknowledged" : true, "deletedCount" : X }
Is there a predefined type for this in Mongo? Or do I need to manually define it myself?
This problem has become apparent during an upgrade from an older version of Mongo to v6, as the response no longer includes the ok
property. It would be helpful to have a type that could catch such changes and show TypeScript errors.
Currently, the code snippet looks like this:
const res = await this.deleteMany(query) // res is currently an any type
if (res.deletedCount > 10) {
// do something
} else {
// do something else
}
The main issue here is that res
is typed as any
. I am wondering if I need to create a custom type or if there is a pre-existing one that can be imported to handle potential changes in future versions.
Any insights would be appreciated. Thanks!