mingo
Version:
MongoDB query language for in-memory objects
19 lines (18 loc) • 478 B
JavaScript
import { computeValue } from "../../core/_internal";
import { Lazy } from "../../lazy";
import { $sort } from "../pipeline/sort";
import { $push } from "./push";
const $topN = (collection, expr, options) => {
const copts = options;
const { n, sortBy } = computeValue(
copts?.local?.groupId,
expr,
null,
copts
);
const result = $sort(Lazy(collection), sortBy, options).take(n).collect();
return $push(result, expr.output, copts);
};
export {
$topN
};