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

cantina-models-mongo

v4.1.4

Published

MongoDB store implementing a modeler-compatible API for cantina-models

Downloads

9

Readme

cantina-models-mongo

MongoDB models for Cantina applications implementing a modeler-compatible API extended with additional functionality.

Provides

  • app.createMongoCollection (name, options) - a MongoDB collection factory

See cantina-models for basic documentation.

Extended Functionality (differences from modeler)

Private Properties

A collection can be created with an optional array of privateProperties:

app.createMongoCollection('foo', {
  privateProperties: ['secret_key']
});

Private properties will be excluded from all models returned by the core api methods (e.g., load). Note that if the core method was invoked with a copy of a model with private properties present, those properties will remain present on the model when any events and hooks are triggered.

Unchangeable Properties

When updating an existing model, any values in the update document for the id, rev, created, and updated properties will be discarded, these are intended to be maintained only by the store.

Arbitrary Queries Parameters

collection#load and collection#list can optionally use the first parameter as a MongoDB query object. So, the call signatures become:

  • load(id|model|query, [callback])
  • list([query], [options], callback) - where options is required if query is provided

Patch Updates

collection#save does not require the full model to perform an update. Only the properties present in the model will be set (using MongoDB $set).

Changed Attributes Hash

When saving changes to an existing model, the model passed to the save and afterSave hooks and passed to the callback will have an extra property, _changed, containing a hash of the properties being saved (not necessarily representing a change in value from the model's previous value).

Deep keys in the _changed hash are "flattened" (like you would access them in in a query or update document), e.g.:

{
  a: 1,
  b: false,
  c: { a: 'foo' },
  d: { b: { x: [ 'a', 'b' ] } }
  e: { y: undefined }
  _changed: {
    a: true,
    b: true,
    'c.a': true,
    'd.b.x': true,
    'e.y': true
  }
}

MongoDB Native Options

Any options provided when calling the core api methods will be passed to MongoDB. So, e.g., field projections are possible.

MongoDB Native Methods

All MongoDB native methods are proxied on the collection, prefixed with an underscore (e.g., MongoCollection#update() is accessible as collection._update()).

N.B. cantina-models events and hooks will not be triggered for any of native method calls.


Developed by Terra Eclipse

Terra Eclipse, Inc. is a nationally recognized political technology and strategy firm located in Santa Cruz, CA and Washington, D.C.