🧵aggregate()
Aggregate Options
$match?: Partial<ExtractSchemaType<T> | Record<any, aggregateOperators>>;
$group?: Partial<ExtractSchemaType<T> | Record<any, Partial<groupOptions<T>>>>;
$sort?: Partial<Record<keyof ExtractSchemaType<T>, 1 | -1>>;
$skip?: number;
$limit?: number;
$project?: Partial<Record<keyof ExtractSchemaType<T>, 1 | 0 | true | false>>;
$facet?: Partial<aggregateOptions<T>[]>;
$unwind?: Partial<ExtractSchemaType<T> | Record<any, aggregateOperators>>;
$addFields?: object | Record<any, aggregateOperators>;
$count?: keyof ExtractSchemaType<T>;
$unset?: (keyof ExtractSchemaType<T>)[] | string[];
$set?: object;
Group Operators
$sum?: keyof ExtractSchemaType<T>;
$avg?: keyof ExtractSchemaType<T>;
$min?: keyof ExtractSchemaType<T>;
$max?: keyof ExtractSchemaType<T>;
$count?: keyof ExtractSchemaType<T>;
$col?: keyof ExtractSchemaType<T>;
Aggregate Operators
$eq?: any;
$gt?: any;
$gte?: any;
$lt?: any;
$lte?: any;
$ne?: any;
$in?: any;
$nin?: any;
$exists?: any;
$match?: any;
$or?: any;
$and?: any;
$notRegexp?: any;
$iRegexp?: any;
$notIRegexp?: any;
$overlap?: any;
$adjacent?: any;
$strictLeft?: any;
$strictRight?: any;
$noExtendRight?: any;
$noExtendLeft?: any;
$col?: any;
$substring?: any;
$placeholder?: any;
$regex?: any;
$all?: any;
$startsWith?: any;
$endsWith?: any;
$like?: any;
$notLike?: any;
$iLike?: any;
$notILike?: any;
$contains?: any;
$contained?: any;
$any?: any;
$between?: any;
$notBetween?: any;
$is?: any;
$type?: any;
$literal?: any;
$fn?: any;
$json?: any;
$cast?: any;
$size?: any;
$ceil?: any;
$floor?: any;
$round?: any;
$abs?: any;
$sqrt?: any;
$log?: any;
$log2?: any;
$log10?: any;
$exp?: any;
$pow?: any;
$acos?: any;
$asin?: any;
$atan?: any;
$cos?: any;
$cot?: any;
$sin?: any;
$tan?: any;
$radians?: any;
$degrees?: any;
$random?: any;
Example
import { Model, Schema, Types } from 'cherry3';
const schema = Schema({
name: String,
surname: Types.String,
age: Types.Number,
classNumber: Number,
achievements: { type: Array, default: [] },
closeFriends: Object
});
const model = new Model('classList',schema)
(async() => {
var result = await model.aggregate([
{ $match: { name: { $in: ["five","so"] }, age: { $gte: 10 } } },
{ $project: { name: true, surname: 1, age: true } },
{ $sort: { age: -1 } }
]);
console.log(result);
/*
[
...{}
]
*/
})();
Last updated