Efficient paging in MongoDB using mgo.v2 and MongoDB > 4.2

 ̄綄美尐妖づ 提交于 2020-04-16 02:59:05

问题


I have already looked at Efficient paging in MongoDB using mgo and asked https://stackoverflow.com/review/low-quality-posts/25723764

I got the excelent response provided by @icza who shares his library https://github.com/icza/minquery.

However, as he said, "Starting with MongoDB 4.2, an index hint must be provided. Use the minquery.NewWithHint() constructor."

The problem is that minquery.NewWithHint() constructor seems to only be available in version 2.0.0, which changed gopkg.in/mgo.v2 support for github.com/globalsign/mgo support.

How can I solve this problem ?


回答1:


gopkg.in/mgo.v2 has long gone unmaintained. The easiest solution for you would be to switch to the github.com/globalsign/mgo mgo driver. It has identical API, so most likely you only have to change the import paths. It is sill somewhat supported, but I believe it will fade away in favor of the official mongo-go driver. If you would choose to switch to mongo-go, that has "built-in" support for specifying the index min parameter for queries. But know that the mongo-go driver has different API.

Another option would be to fork minquery, and apply the commits I made to the v2.0.0 version, including support for the index hints.



来源:https://stackoverflow.com/questions/60922650/efficient-paging-in-mongodb-using-mgo-v2-and-mongodb-4-2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!