mongodb 聚合限制html
使用 aggregate 命令的聚合操做有如下限制:java
管道不能操做一下類型的值: Binary, Symbol, MinKey, MaxKey, DBRef, Code, ``CodeWScope``。web
pipeline 輸出只能容納16兆字節. 若是你的結果集超過此限制, aggregate 命令將生成一個錯誤。mongodb
若是任何一個聚合操做消耗超過10%的系統RAM,運行中會產生一個錯誤。app
mongodb中文翻譯文檔地址:http://mongodb-documentation.readthedocs.org/en/latest/applications/aggregation.html#id23spa
mongodb英文文檔地址:https://docs.mongodb.org/ecosystem/tools/munin/命令行
若是超出100兆內存,則Mongodb就會報錯:Exceeded memory limit for $group, but not allow enternal sort, put allowDiskUse true翻譯
在命令行中是這樣的:code
db.CRM_CSS_REPAIR_ORDER_TABLE.aggregate( [ { $group : { _id : { key1:"$COLUMN_NAME" "key2_date_year":{$year:"$produce_date"}, "key3_date_month":{$month:"$produce_date"} }, count: { $sum: 1 }, min_RECORD_DATE:{$min:'$RECORD_DATE'}, min_purchase_date:{$min:'$purchase_date'} } }, { $sort:{ count:-1 } } ] )
在java類中是這樣的:orm
List<Document> pipeline = Arrays.asList( new Document("$group", new Document( "_id", new Document("MATERIAL_CODE","$MATERIAL_CODE") .append("PROVINCE_NAME","$PROVINCE_NAME") .append("RECORD_DATE_YEAR",new Document("$year","$RECORD_DATE")) .append("RECORD_DATE_MONTH",new Document("$month","$RECORD_DATE")) ) .append("count", new Document("$sum",1)) .append("min_produce_date",new Document("$min","$produce_date")) ) ), new Document("$sort", new Document("count", -1)) ); AggregateIterable<Document> iterable = CRM_CSS_REPAIR_ORDER_TABLE_coll.aggregate(pipeline).allowDiskUse(true); int i=0; for (Document d : iterable){ i++; Document _id=(Document)d.get("_id"); String ITEM_NUMBER=_id.getString("MATERIAL_CODE"); }
務必加上allowDiskUse,還有其餘的,好比
batchSize(int var1)
maxTime(long var1, TimeUnit var3);
useCursor(Boolean var1);