You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

mongodb-pipelinejs

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mongodb-pipelinejs

Use short and sweet JS syntax (instead of JSON) to compose and cleanly format MongoDB aggregations.

0.0.1
Source
npmnpm
Version published
Weekly downloads
12
300%
Maintainers
1
Weekly downloads
 
Created
Source

MongoDB PipelineJS

Aggregation Syntax for Javascript; Use Javascript syntax—instead of JSON—to compose MongoDB aggregations.

Browse Reference Documentation »

Installation

Add mongodb-pipelinejs to your MongoDB project:

With Yarn: yarn add mongodb-pipelinejs

With NPM: npm install mongodb-pipelinejs

Usage

Example needs refinement...

const $ = require('mongodb-pipelinejs');

mongoDB.collection('transactions').aggregate([
  $.match({
    userId: MY_USER_ID,
    amount: $.gte(100),
    type: $.in(['sale', 'transfer']),
    status: $.neq('new'),
  }),
  $.redact($.switch('$$PRUNE')
    .case($.eq('$type', 'sale')),
  }),
  $.addFields({
    payments: $.filter('$payments', 'payment', $.in('$$payment.status', ['complete', 'approved'])),
  }),
  $.unwind('$payments'),
  $.group({
    _id: '$transactionId',
    payments: $.push('$payments.paymentId'),
    amountDue: $.last('$amount'),
    amountPaid: $.sum('$payments.amount'),
  })
  $.unwind('$payments', true)
]).toArray();

FAQs

Package last updated on 02 Jan 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts