You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm encountering an issue with AdminJS when applying filters to a Mongoose model. The error message I'm seeing is "TypeError: this.MongooseModel.count is not a function".
Here's the relevant code from @adminjs/mongoose/resource.js:54:39:
The error starts when this.MongooseModel.count(convertFilter(filters)) is called.
My @adminjs/express and mongoose packages are up to date. I've also verified that my Mongoose model is correctly defined and exported, and it's correctly imported in my AdminJS configuration.
The issue only occurs when applying filters. The data is displayed correctly without filters.
According to mongoose docs, the count function in Mongoose is deprecated and it's recommended to use countDocuments or estimatedDocumentCount instead. However, since I'm using AdminJS, I don't have direct control over this function call.
Seems like changing it to return this.MongooseModel.countDocuments(convertFilter(filters)) fixes the issue.
TypeError: this.MongooseModel.count is not a function
at Resource.count (node_modules/@adminjs/mongoose/lib/resource.js:54:39)
at Object.handler (node_modules/adminjs/lib/backend/actions/list/list-action.js:75:34)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async ActionDecorator.handler (node_modules/adminjs/lib/backend/decorators/action/action-decorator.js:56:19)
at async node_modules/@adminjs/express/lib/buildRouter.js:24:22
The text was updated successfully, but these errors were encountered:
Seems like changing it to return this.MongooseModel.countDocuments(convertFilter(filters)) fixes the issue.
We've tried that before and countDocuments(convertFilter(filters)) actually returned wrong counts above resource's list of records, that's why we reverted back to using count. PRs that implement countDocuments properly are welcome though.
What happened?
I'm encountering an issue with AdminJS when applying filters to a Mongoose model. The error message I'm seeing is "TypeError: this.MongooseModel.count is not a function".
Here's the relevant code from
@adminjs/mongoose/resource.js:54:39
:The error starts when
this.MongooseModel.count(convertFilter(filters))
is called.My
@adminjs/express
andmongoose
packages are up to date. I've also verified that my Mongoose model is correctly defined and exported, and it's correctly imported in my AdminJS configuration.The issue only occurs when applying filters. The data is displayed correctly without filters.
According to mongoose docs, the
count
function in Mongoose is deprecated and it's recommended to usecountDocuments
orestimatedDocumentCount
instead. However, since I'm using AdminJS, I don't have direct control over this function call.Seems like changing it to
return this.MongooseModel.countDocuments(convertFilter(filters))
fixes the issue.Please help me resolve this issue. Thank you.
Bug prevalence
Every time i apply filters.
AdminJS dependencies version
Relevant log output
The text was updated successfully, but these errors were encountered: