MongoDB内存不足怎么情况,怎么解决
Admin 2022-05-28 群英技术资讯 669 次浏览
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,在使用一个数据库前必不可少的就是安装和卸载,所以下面这篇文章主要给大家介绍了关于Mac系统中mongoDB安装与卸载的相关资料,需要的朋友可以参考借鉴,下面来一起看看吧。
MongoDB 概念解析 不管我们学习什么数据库都应该学习其中的基础概念,在mongodb中基本的概念是文档、集合、数据库,下面我们挨个介绍。 下表将帮助您更容易理解Mongo中的一些概念: SQL术语/概念 MongoDB术语/概念 解释/说明 database database 数据库 table collection 数据库表/集合 row document 数据记录行/文档 column field 数..
MongoDB是一个跨平台,面向文档的数据库,提供高性能,高可用性和易于扩展。MongoDB是工作在集合和文档上一种概念。下面通过本文给大家分享Centos7安装和卸载Mongodb数据库的方法,需要的朋友参考下吧
在mongodb的使用过程中都知道关系型数据库都是有权限的,而用户只有读取权限,那么你知道mongodb怎么添加管理员和普通用户吗?
接触过SQL都知道,索引是很重要的内容。在MongoDB中索引也是很重要的,数据库的索引能够提高查询操作的性能,能快速获取我们想要的介绍。下面我们就一起来了解一下MongoDB索引。
成为群英会员,开启智能安全云计算之旅
立即注册Copyright © QY Network Company Ltd. All Rights Reserved. 2003-2020 群英 版权所有
增值电信经营许可证 : B1.B2-20140078 粤ICP备09006778号 域名注册商资质 粤 D3.1-20240008