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

node-bits-mongo

v0.0.20

Published

Provides the logic for connecting bits to a mongo database

Downloads

2

Readme

node-bits-mongo

node-bits-mongo allows a node-bits app access to a mongo database. node-bits-mongo will use the schema defined by other bits in the loadSchema step as its schema definition.

Install

npm install node-bits-mongo --save

or

yarn add node-bits-mongo

Configuration

nodeBitsMongo({
  connection: 'connection-string',
  hooks: [
    nodeBitsPassword(),
  ],
}),

connection

This is the connection string to the mongo database.

runSeeds

If runSeeds is included and set to true, node-bits-mongo will look for seeds as defined in the schema, and insert them into the database

hooks

hooks is an array of functions that accepts a single args parameter. The property values passed to args and optional actions varies by operation and are described below:

Before execution
  • name: the name of the model
  • schema: the defined schema object for this model
  • action: QUERY, INSERT, UPDATE, DELETE
  • stage: BEFORE, AFTER
  • options: these are the options passed to the database on the query

Any value returned will be used as the options forward. If you do not want this effect, return null.

After Execution
  • name: the name of the model
  • schema: the defined schema object for this model
  • action: QUERY, INSERT, UPDATE, DELETE
  • stage: BEFORE, AFTER
  • options: these are the options passed to the database on the query
  • results: the results returned by the database

node-bits-password

node-bits-password implements the logic for the PASSWORD type fields and is a common hook. See the bit's documentation for more information.

Methods

connect

This will open a connection to the database.

rawConnection

Sometimes you need the raw mongo connection to do something that node-bits-mongo hasn't exposed. This method will return the mongoosejs connection to you.

getModel

getModel(name)

This will return to you the mongoosejs model.

findById

findById(name, id)

The name of the model, the id to search for.

Will return an object if found, if not will return null.

find

find(name, options)

The name of the model, the options to use for searching.

Will return the results for the options supplied, null is supplied, it will return all records for the model

Options

All options are not required and can be used in any combination.

  • select: an array of field names to include in the results
  • orderby: an array of objects that define the order of the result. The format of is item is as follows: {field: '', direction: ''}.
  • start: the index of the result set to start from (alternatively parameter can be named skip)
  • max: the number of records to return in the results (alternatively parameter can be named limit)
  • where: a complex object that contains the
  • includeMetaData: an array of options to return wrapped around the result set. If supplied the format of the result will be value:[rows], ...{keys as supplied}
Where

The where clause is specified as a complex object made up of key, value pairs. Many times the values for a key are a complex object themselves, representing the operations and values.

node-bits-mongo supports the following operators: eq, ne, gt, ge, lt, le, like, startsWith, endsWith, and, or.

Example (all orders with a total greater than or equal to $5.00):

database.find('order', {
  where: {
    total: { ge: 5 },
  },
};ß
Include Meta Data

The following options are understood for metadata, and the constants can be found in node-bits.

  • COUNT
  • START
  • MAX

To allow for different return keys, the format of each item in the array is as follows: {key: '', value: ''}

create

create(name, data)

The name of the model, the data to insert.

Will return the object inserted with all autogenerated fields

update

update(name, id, data)

The name of the model, the id of the record to update, the data to use as the new version of the object.

Will return the object updated with all autogenerated fields

delete

delete(name, id)

The name of the model, the id of the object to delete.