mongoose-aggregation-pipeline-builder
TypeScript icon, indicating that this package has built-in type declarations

0.4.0 • Public • Published

PipelineStageBuilder

A fluent builder for MongoDB aggregation pipeline stages

new PipelineStageBuilder().$match({ _id: "_id" }).$project({ _id: 1 });
const aggregation = new PipelineStageBuilder()
  .$match({ _id: "_id" })
  .$project({ _id: 1 })
  .build();

const result = await model.aggregate(aggregation);

Migration

Generate string template from array of aggregation pipeline stages. This makes it easier to convert an array of stages into a string template

PipelineStageBuilder.fromArray([
  {
    $match: {
      _id: "_id",
    },
  },
  {
    $project: {
      _id: 1,
    },
  },
]);

Supported aggregation pipeline stages:

  • $addFields
  • $bucket
  • $bucketAuto
  • $collStats
  • $count
  • $densify
  • $fill
  • $facet
  • $geoNear
  • $graphLookup
  • $group
  • $indexStats
  • $limit
  • $listSessions
  • $lookup
  • $match
  • $merge
  • $out
  • $planCacheStats
  • $project
  • $redact
  • $replaceRoot
  • $replaceWith
  • $sample
  • $search
  • $set
  • $setWindowFields
  • $skip
  • $sort
  • $sortByCount
  • $unionWith
  • $unset
  • $unwind

Package Sidebar

Install

npm i mongoose-aggregation-pipeline-builder

Weekly Downloads

1

Version

0.4.0

License

ISC

Unpacked Size

27.9 kB

Total Files

21

Last publish

Collaborators

  • aniketbiprojit