MongoDB内存不足怎么情况,怎么解决
Admin 2022-05-28 群英技术资讯 603 次浏览
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数据库的特点:1、易扩展性;2、网站数据具有高性能;3、具有高伸缩性的场景;4、存储动态性;5、速度与持久性。
MongoDB监控工具有哪些?在MongoDB中,有自带两个监控的工具,分别是mongostat和mongotop,很多刚接触MongoDB的朋友可能对于这两个工具的使用不是很了解,对此这篇文章就主要给大家介绍一下关于mongostat和mongotop的使用,感兴趣的朋友可以了解一下。
读取mongodb数据库文件大小的方法:先使用“use databasename”命令选择数据库,然后使用db.stats()命令即可查看数据库文件大小。
mongodb创建账号密码的方法:先使用use命令选择一个数据库,然后使用db.createUser()方法即可创建用户名密码。
MongoDB 全文检索 全文检索对每一个词建立一个索引,指明该词在文章中出现的次数和位置,当用户查询时,检索程序就根据事先建立的索引进行查找,并将查找的结果反馈给用户的检索方式。 这个过程类似于通过字典中的检索字表查字的过程。 MongoDB 从 2.4 版本开始支持全文检索,目前支持15种语言的全文索引。 danish dutch english finnish french german hungari..
成为群英会员,开启智能安全云计算之旅
立即注册Copyright © QY Network Company Ltd. All Rights Reserved. 2003-2020 群英 版权所有
增值电信经营许可证 : B1.B2-20140078 粤ICP备09006778号 域名注册商资质 粤 D3.1-20240008