UNPKG

mingo

Version:

MongoDB query language for in-memory objects

18 lines (17 loc) 490 B
import { computeValue } from "../../core/_internal"; import { assert } from "../../util"; import { $push } from "./push"; const $firstN = (collection, expr, options) => { const copts = options; const m = collection.length; const n = computeValue(copts?.local?.groupId, expr.n, null, copts); assert(n > 0, "$firstN: 'n' must resolve to a positive integer."); return $push( m <= n ? collection : collection.slice(0, n), expr.input, options ); }; export { $firstN };