欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

解決mongodb內(nèi)存不足的方法-創(chuàng)新互聯(lián)

創(chuàng)新互聯(lián)www.cdcxhl.cn八線動態(tài)BGP香港云服務(wù)器提供商,新人活動買多久送多久,劃算不套路!

成都創(chuàng)新互聯(lián)主營青川網(wǎng)站建設(shè)的網(wǎng)絡(luò)公司,主營網(wǎng)站建設(shè)方案,app軟件開發(fā)公司,青川h5小程序制作搭建,青川網(wǎng)站營銷推廣歡迎青川等地區(qū)企業(yè)咨詢

小編給大家分享一下解決mongodb內(nèi)存不足的方法,希望大家閱讀完這篇文章后大所收獲,下面讓我們一起去探討方法吧!

mongodb每一個文檔默認只有16M。聚合的結(jié)果是一個BSON文檔,當(dāng)超過16M大小時,就會報內(nèi)存不夠錯誤。

exceeded memory limit for $group.but didn't allow external sort.

可以采用打開使用磁盤來解決大小問題。例如

db.flowlog.aggregate([{$group:{_id:"$_id"}}], {allowDiskUse: true})

java代碼片段

AggregationOptions options = new AggregationOptions.Builder().allowDiskUse(true).build();

Aggregation agg = Aggregation.newAggregation().withOptions(options);

但是如果結(jié)果集超過了16M,那么依然會報錯誤。

采用一個下面的聚合方法

Aggregation agg = Aggregation.newAggregation(
                    Aggregation.group(field1
                            , field2
                            , field3)
                            .sum(field4).as("sampleField1")
                            .sum(field5).as("sampleField2"),
                    Aggregation.project(field4, field5),
                    new AggregationOperation() { 
                        @Override
                          public DBObject toDBObject(AggregationOperationContext context) {
                            return new BasicDBObject("$out", "test");
                        }
                    }).withOptions(options);
  mongo.aggregate(agg, sourceCollection, Test.class);

 如果要在聚合的時候增加一個常量,可采用以下形式

Aggregation agg = Aggregation.newAggregation(
                    Aggregation.group(
                            , OnofflineUserHistoryField.MAC
                            , StalogField.UTC_CODE)
                            .sum(OnofflineUserHistoryField.WIFI_UP_DOWN).as(OnofflineUserHistoryField.WIFI_UP_DOWN)
                            .sum(OnofflineUserHistoryField.ACTIVE_TIME).as(OnofflineUserHistoryField.ACTIVE_TIME),
                    Aggregation.project("mac","buildingId","utcCode",OnofflineUserHistoryField.ACTIVE_TIME, OnofflineUserHistoryField.WIFI_UP_DOWN).and(
                    new AggregationExpression() {
                        @Override
                        public DBObject toDbObject(AggregationOperationContext context) {
                            return new BasicDBObject(
                                    "$cond", new Object[]{
                                            new BasicDBObject(
                                                "$eq", new Object[]{ "$tenantId", 0}
                                            ),
                                            20161114,
                                            20161114
                                     });
                        }
                    }).as("day").andExclude("_id"),            或者
                      and(new AggregationExpression() {
             @Override
             public DBObject toDbObject(AggregationOperationContext context) { 

                         return new BasicDBObject("$add", new Object[] { 20141114 });
            }  

                    }).as("day").andExclude("_id"),
            new AggregationOperation() { 
                        @Override
                          public DBObject toDBObject(AggregationOperationContext context) {
                            return new BasicDBObject("$out", "dayStaInfoTmp");
                        }
                    }).withOptions(options);

看完了這篇文章,相信你對解決mongodb內(nèi)存不足的方法有了一定的了解,想了解更多相關(guān)知識,歡迎關(guān)注創(chuàng)新互聯(lián)-成都網(wǎng)站建設(shè)公司行業(yè)資訊頻道,感謝各位的閱讀!

標(biāo)題名稱:解決mongodb內(nèi)存不足的方法-創(chuàng)新互聯(lián)
標(biāo)題路徑:http://chinadenli.net/article4/cohcie.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站收錄App開發(fā)搜索引擎優(yōu)化營銷型網(wǎng)站建設(shè)網(wǎng)站維護響應(yīng)式網(wǎng)站

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

小程序開發(fā)