npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

mongo-helpers

v0.0.7

Published

The supporting API for mongodb data and collection operations

Downloads

9

Readme

mongo-helpers

The supporting API for mongodb data and collection operations, overwrite meteor/leaf4monkey:mongo-helpers

Installation

npm install mongo-helpers --save

Importing

import {MongoHelpers} from 'mongo-helpers';

or:

const MongoHelpers = require('mongo-helpers').MongoHelpers;

APIs

MongoHelpers.flatten (obj):

Flattening a document {a: {b: [{aa: 1, bb: 1}]}},return {'a.b.0.aa': 1, 'a.b.0.bb': 1}

var o = {a: {b: [{aa: 1, bb: new Date()}]}};
o = JSON.stringify(MongoHelpers.flatten(o)); // '{"a.b.0.aa":1,"a.b.0.bb":"2016-07-06T03:42:53.511Z"}';

MongoHelpers.rebuild (flatten):

MongoHelpers.flatten (obj) reverse operation

MongoHelpers.flattenToModifier (base, mirror, options):

After flattening the incoming document, compare the key value pairs return modifier(include $set and $unset )。

  • arguments:

      `base {Object} `: 需要对比的对象
    
      `mirror {Object|null} `: 作为镜像来完成对比的对象
    
      `options.falsy {Array.<any>|undefined} `: 自定义的假值列表,如果 `base` 中的值在该列表中,则对应的属性将被纳入 unset 集,默认值为 `[null, undefined]`。
    
      `options.unsetNonProp {boolean} `: 是否将base中不包含的属性加入到 `unset` 集中,如果设置为 `true`,则需要先检查 `base` 中是否包含指定属性,再检查其值是否在假值列表中。
    
      `options.unsetAs {any} `: 统一设置 `unsetter` 中的键值,建议按照习惯设置为 `1` 或 `true`,如果传入的 `mirror` 参数为 `null`,则强制设置为 `true`,否则默认被设置为 `base` 对象中的值。

MongoHelpers.diffToFlatten (base, mirror, options):

将传入的文档扁平化后,对比键值对,获得两个对象的差异部分,仅在 mirror 中存在的值将在返回的结果中被设置为 undefined。参数列表与 MongoHelpers.flattenToModifier (base, mirror, options) 一致,但不可设置 options.unsetAs