12345678910111213141516171819202122232425 |
- 'use strict';
- module.exports = function(schema, options) {
- // 为全局mongodb添加一个解决 结果集 在分片模式下 大于101 Cursor no found 的问题
- schema.statics.aggregateFix = async function(agg) {
- agg.push({
- $group: { _id: null, data: { $push: '$$ROOT' } },
- });
- const result = await this.aggregate(agg).allowDiskUse(true);
- if (result && result.length > 0) {
- return result[0].data;
- }
- return [];
- };
- // 添加一个无条件分组的简化操作
- schema.statics.aggregateNGroup = async function(agg) {
- const result = await this.aggregate(agg).allowDiskUse(true);
- if (result && result.length > 0) {
- return result[0];
- }
- return {};
- };
- };
|