gpt4 book ai didi

java - MongoDB 明显太大 16mb 上限

转载 作者:IT老高 更新时间:2023-10-28 13:20:31 28 4
gpt4 key购买 nike

我有一个 Mongodb 集合。简单地说,它有两列:用户和网址。它有 39274590 行。该表的键是 {user, url}。

使用 Java,我尝试列出不同的 url:

  MongoDBManager db = new MongoDBManager( "Website", "UserLog" );
return db.getDistinct("url");

但我收到一个异常:

Exception in thread "main" com.mongodb.CommandResult$CommandFailure: command failed [distinct]: 
{ "serverUsed" : "localhost/127.0.0.1:27017" , "errmsg" : "exception: distinct too big, 16mb cap" , "code" : 10044 , "ok" : 0.0}

我该如何解决这个问题?有没有plan B可以避免这个问题?

最佳答案

在 2.6 版中,您可以使用聚合命令来生成单独的集合: http://docs.mongodb.org/manual/reference/operator/aggregation/out/

对于大多数查询,这将绕过 mongodb 的 16mb 限制。您可以在此处阅读有关在 mongodb 2.6 中的大型数据集上使用聚合框架的更多信息: http://vladmihalcea.com/mongodb-2-6-is-out/

要使用聚合框架进行“不同”查询,请按字段分组。

db.userlog.aggregate([{$group: {_id: '$url'} }]); 

注意:我不知道这对 Java 驱动程序是如何工作的,祝你好运。

关于java - MongoDB 明显太大 16mb 上限,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27323107/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com