mongodb中查询的问题 [英] Problems with queries in mongodb
问题描述
我开始使用 MongoDB
并且在咨询查询时遇到问题.总是出现以下错误.
I am starting to use MongoDB
and I have a problem in consultation with queries. The following error always happens.
db.user_tracking.distinct("q")Sun May 19 20:02:01.785 JavaScript 执行失败:distinct 失败:{"errmsg" : "异常:明显太大,16mb 上限",代码":10044,好的":0在 src/mongo/shell/collection.js:L879
db.user_tracking.distinct("q") Sun May 19 20:02:01.785 JavaScript execution failed: distinct failed: { "errmsg" : "exception: distinct too big, 16mb cap", "code" : 10044, "ok" : 0 } at src/mongo/shell/collection.js:L879
谁能告诉我如何解决这个问题?谢谢.
Can anyone tell me how to solve this? Thanks.
推荐答案
好吧,您在 mongoDB当您调用 distinct()
方法时,您将收集该给定字段的所有不同值的数组.如果这样的结果大于 16MB,你会得到这个错误.
Well you are running into the 16MB document result in mongoDB
When you call the distinct()
method you will collect back an array of all distinct values for that given field. If such result is bigger than 16MB you'll get this error.
为了避免这种情况,您可能需要使用聚合框架,您可以在其中收集相同的输出但对结果进行分页:
To avoid this you may want to use the aggregation framework where you can collect the same output but paginating the result ex:
db.user_tracking.aggregate( {$limit: X}, {$skip: Y}, {$group: {_id: "$q"} )
循环 X 和 Y 值,您就克服了 16MB 的限制.
Loop around X and Y values and you overcome the 16MB limitation.
否.
这篇关于mongodb中查询的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!