mongo-pipeline
TypeScript icon, indicating that this package has built-in type declarations

1.0.11 • Public • Published

Mongo aggregation pipeline

This module provide a nice way to work with aggregations of mongodb using, for example, the mongoose in nodejs.

Basic example

const mongoose = require('mongoose');
const { PipelineBuilder } = require('mongo-pipeline');

const pipeline = new PipelineBuilder();

const collection = await pipeline
  .match({ _id: mongoose.Types.ObjectID('xxxxxxxxxxxxxxxxxxx') })
  .lookupAndUnwind('collections', 'field', '_id', 'new')
  .log()
  .aggregateOneWith(mongoose.model('Collection'));
/*
[
  {
    $match: {
      _id: 'xxxxxxxxxxxxxxxxxxx'
    }
  },
  {
    "$lookup": {
      "from": "collections",
      "localField": "field",
      "foreignField": "_id",
      "as": "new"
    }
  },
  {
    "$unwind": {
      "path": "$new"
    }
  }
]
*/

See others examples in test repository.

Dependencies (0)

    Dev Dependencies (0)

      Package Sidebar

      Install

      npm i mongo-pipeline

      Weekly Downloads

      0

      Version

      1.0.11

      License

      MIT

      Unpacked Size

      11.7 kB

      Total Files

      6

      Last publish

      Collaborators

      • danielfarina