选项allowDiskUse的MongoDB聚合仍然超过最大文档大小?

时间:2017-05-26 04:45:37

标签: java mongodb

当我尝试使用aggregate()加入2个集合时,我从MongoDB收到此错误消息:

  

聚合结果超出最大文档大小(16MB)

经过一些搜索,我发现我必须将allowDiskUse(true)选项添加到我的aggregate()(link)中。但它似乎不起作用,每当我运行时,我仍然会收到错误消息,我在代码的某个地方做错了吗?请帮忙。

我的代码:

    try {
        MongoClient mc = DBConnection.createConnection();
        DB db = mc.getDB("testdb");
        DBCollection postTable = db.getCollection("posts");
        AggregateIterable<BasicDBObject> joinedTable;
        BasicDBObject lookup = new BasicDBObject();
        lookup.put("from", "analytics");
        lookup.put("localField", "_id");
        lookup.put("foreignField", "_id");
        lookup.put("as", "views");
        joinedTable = (AggregateIterable<BasicDBObject>) postTable.aggregate(
                Arrays.asList(new BasicDBObject("$lookup", lookup)),
                AggregationOptions.builder().allowDiskUse(Boolean.TRUE).build());
        for (BasicDBObject obj: joinedTable){
            System.out.println(obj);
        }
    } catch (Exception ex){
        ex.printStackTrace();
    }

0 个答案:

没有答案