mixmaxhq / mongo-cursor-pagination

Cursor-based pagination for Mongo
https://www.mixmax.com/careers
MIT License
229 stars 72 forks source link

Unsupported BSON version, bson types must be from bson 5.0 or later when used with mongoose 7.0.0 #349

Open Fasunle opened 1 year ago

Fasunle commented 1 year ago

Reproduce Bug

In order to reproduce this bug, use mongo-cursor-pagination (8.1.2 or 8.1.3) with mongoose (7.0.0).

The error occurs whenever next page query is added to paginate function.

Fasunle commented 1 year ago

Please, let me know if you need any further information to help you solve this bug

KDDeveloper commented 1 year ago

I dont have a solution to it but, I had updated my mongo server which cleared my DB and collections, as soon as imported them again the error went away.

Fasunle commented 1 year ago

So, it means it could be that my mongo server is obsolete. Interesting! I will try upgrading and see how it goes.

KDDeveloper commented 1 year ago

I faced the same error second time again, this was due to using an older version of mongoose(5.1.1) to create a new Objectid, updating it to v 7.0.3 resolved the issue. If someone could explain why does this error occur that would be awesome. All the best

truthseekers commented 1 year ago

I'm having the same problem. Followed @KDDeveloper 's suggestion and now I'm just getting "null" for ids. I'm using GraphQL and most of the time it's smart enough to convert _id to id, but now I have to do it manually.

I also had to upgrade to MongoDB 6.0 to fix the BSON types error. Deleting and re-adding collections did not fix the issue.

wvkehoe commented 1 year ago

I was able to work-around this issue by forcing newer BSON and mongodb versions using this in my project's package.json file: "overrides": { "mongoose": { "mongodb": "5.2.0", "bson": "5.2.0" }, "mongo-cursor-pagination": { "mongodb": "5.2.0", "bson": "5.2.0" } }

alexperry870 commented 3 months ago

work around:

"resolutions": { "bson": "6.8.0", "mongo-cursor-pagination/bson": "6.8.0", "mongodb/bson": "6.8.0", "mongoose/mongodb/bson": "6.8.0" }

I will try to fix it with a PR.