MongoDB内存不足怎么情况,怎么解决
Admin 2022-05-28 群英技术资讯 1150 次浏览
这篇文章主要介绍“MongoDB内存不足怎么情况,怎么解决”的相关知识,下面会通过实际案例向大家展示操作过程,操作方法简单快捷,实用性强,希望这篇“MongoDB内存不足怎么情况,怎么解决”文章能帮助大家解决问题。
mongodb每一个文档默认只有16M。聚合的结果是一个BSON文档,当超过16M大小时,就会报内存不够错误。
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);
但是如果结果集超过了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);
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:mmqy2019@163.com进行举报,并提供相关证据,查实之后,将立刻删除涉嫌侵权内容。
猜你喜欢
相信很多人应该都有文件、数据备份的习惯,其中MongoDB存储的数据量较大,因此备份文件也是比较大,那么就需要对MongoDB备份压缩,下面小编就给大家分享关于MongoDB实现备份压缩的方法,需要的朋友可以参考。
mongodb使用方法:使用mongoimport --db dbName --collection collectionName --file filePath命令导入json文件,然后就可以在mongodb中使用json文件。
文本主要给大家介绍的是关于MongoDB查询耗时的方法,小编觉得比较实用,因此分享给大家作参考,需要的朋友可以参考参考,下面就跟随小编一起看看吧。
更新数据操作是数据库的日常操作,那么mongodb更新数据的方法有哪些呢?下面就给大家分享关于mongodb更新数据的方法,有字段更新,数组更新等等方法,接下来跟随小编一起看看吧。
这篇文章给大家分享的是mongodb数据库中CURD怎么操作的内容,小编觉得挺实用的,因此分享给大家做个参考,更兴趣的朋友就跟随小编一起来学习吧。
成为群英会员,开启智能安全云计算之旅
立即注册关注或联系群英网络
7x24小时售前:400-678-4567
7x24小时售后:0668-2555666
24小时QQ客服
群英微信公众号
CNNIC域名投诉举报处理平台
服务电话:010-58813000
服务邮箱:service@cnnic.cn
投诉与建议:0668-2555555
Copyright © QY Network Company Ltd. All Rights Reserved. 2003-2020 群英 版权所有
增值电信经营许可证 : B1.B2-20140078 ICP核准(ICP备案)粤ICP备09006778号 域名注册商资质 粤 D3.1-20240008