问题
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