MongoDB内存不足怎么情况,怎么解决
Admin 2022-05-28 群英技术资讯 1118 次浏览
这篇文章主要介绍“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 高级索引 考虑以下文档集合(users ): { 'address': { 'city': 'Los Angeles', 'state': 'California', 'pincode': '123' }, 'tags..
下面小编就为大家带来一篇基于MongoDB数据库索引构建情况全面分析。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧
MongoDB怎么进行数据更新,用什么方法?一些朋友可能会遇到这方面的问题,对此在下文小编向大家来讲解一下,内容详细,易于理解,希望大家阅读完这篇能有收获哦,有需要的朋友就往下看吧!
mongodb数据库删除语句是db.dropDatabase(),此语句可以删除当前数据库,所以使用此语句需要先使用use命令切换到指定数据库。
MongoDB 数据库引用 在上一章节MongoDB关系中我们提到了MongoDB的引用来规范数据结构文档。 MongoDB 引用有两种: 手动引用(Manual References)DBRefs DBRefs vs 手动引用 考虑这样的一个场景,我们在不同的集合中 (address_home, address_office, address_mailing, 等)存储不同的地址(住址,办公室地址,邮件地址等)。 这样,我们在调..
成为群英会员,开启智能安全云计算之旅
立即注册关注或联系群英网络
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