使用mgo.v2和MongoDB>在MongoDB中进行有效的分页4.2 [英] Efficient paging in MongoDB using mgo.v2 and MongoDB > 4.2

查看:137
本文介绍了使用mgo.v2和MongoDB>在MongoDB中进行有效的分页4.2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经查看了使用mgo在MongoDB中进行有效的分页并问到 https://stackoverflow.com/review/low-quality-posts/25723764

我收到了@icza的出色回答,他分享了他的库 https://github.com/icza/minquery .

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

但是,正如他所说,从MongoDB 4.2开始,必须提供索引提示.请使用minquery.NewWithHint()构造函数."

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

问题在于minquery.NewWithHint()构造函数似乎仅在2.0.0版本中可用,该版本将gopkg.in/mgo.v2支持更改为github.com/globalsign/mgo支持.

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 ?

推荐答案

gopkg.in/mgo.v2长期未维护.最简单的解决方案是切换到github.com/globalsign/mgo mgo驱动程序.它具有相同的API,因此很可能只需更改导入路径.它在某种程度上得到了支持,但我相信它会逐渐消失,取而代之的是 official mongo-go 驱动程序.如果您选择切换到mongo-go,则具有内置"支持,可为查询指定索引min参数.但是请知道mongo-go驱动程序具有不同的API.

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.

另一种选择是派生minquery,并将我所做的提交应用于v2.0.0版本,包括对索引提示的支持.

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.

这篇关于使用mgo.v2和MongoDB>在MongoDB中进行有效的分页4.2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆