Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

xpress-mongo

Package Overview
Dependencies
Maintainers
1
Versions
149
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

xpress-mongo - npm Package Compare versions

Comparing version 2.6.0 to 2.7.0

2

package.json
{
"name": "xpress-mongo",
"version": "2.6.0",
"version": "2.7.0",
"description": "Light Weight ODM for mongoDb NodeJs",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -351,5 +351,19 @@ import ObjectCollection from "object-collection";

* ==> 300
* @param field
* @param match
*/
static sum(field: string, match?: StringToAnyObject): Promise<number>;
/**
* Sum fields in this collection.
* @example
* data: [
* {name: 'john', credit: 100, debit: 400},
* {name: 'doe', credit: 200, debit: 300}
* ]
*
* const sumOfBoth = await Model.sum(['credit', 'debit']);
* ==> {credit: 300, debit: 700}
* const sum = await Model.sum(['credit', 'debit']);
* // {credit: 300, debit: 700}
* // OR
* const sum = await Model.sum({income: 'credit', expense: 'debit'});
* // {income: 300, expense: 700}
*

@@ -359,5 +373,3 @@ * @param fields

*/
static sum(fields: string | StringToAnyObject | string[], match?: StringToAnyObject): Promise<number | {
[name: string]: number;
}>;
static sumMany<T extends string[] | readonly string[] | StringToAnyObject>(fields: T, match?: StringToAnyObject): Promise<T extends string[] | readonly string[] ? Record<T[number], number> : Record<keyof T, number>>;
/**

@@ -364,0 +376,0 @@ * Count Aggregations

@@ -1002,5 +1002,22 @@ "use strict";

* ==> 300
* @param field
* @param match
*/
static async sum(field, match) {
const sum = await this.sumMany([field], match);
return sum[field];
}
/**
* Sum fields in this collection.
* @example
* data: [
* {name: 'john', credit: 100, debit: 400},
* {name: 'doe', credit: 200, debit: 300}
* ]
*
* const sumOfBoth = await Model.sum(['credit', 'debit']);
* ==> {credit: 300, debit: 700}
* const sum = await Model.sum(['credit', 'debit']);
* // {credit: 300, debit: 700}
* // OR
* const sum = await Model.sum({income: 'credit', expense: 'debit'});
* // {income: 300, expense: 700}
*

@@ -1010,7 +1027,5 @@ * @param fields

*/
static async sum(fields, match) {
static async sumMany(fields, match) {
const $group = { _id: null };
const $result = {};
if (typeof fields === "string")
fields = [fields];
const fieldIsArray = Array.isArray(fields);

@@ -1031,5 +1046,7 @@ if (fieldIsArray) {

}
let result = await this.native()
.aggregate([{ $match: match }, { $group }])
.toArray();
const pipeline = [];
if (match)
pipeline.push({ $match: match });
pipeline.push({ $group });
let result = await this.native().aggregate(pipeline).toArray();
if (result.length) {

@@ -1040,3 +1057,3 @@ for (const field of fields) {

}
return fields.length === 1 ? $result[fields[0]] : $result;
return $result;
}

@@ -1043,0 +1060,0 @@ /**

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc