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 🙏

© 2025 – Pkg Stats / Ryan Hefner

just-mongo

v2.2.6

Published

Just using mongoDB

Downloads

77

Readme

Just Mongo 2.2

just-mongo

Simple and fast wrapper for MongoDB.

💪 Motivation

Less code and more action.

Just Mongo allows you to use a simplified API. Inside, we try to use minimalistic solutions that do not steal your time.

You choose the possibilities of the library, and nothing more.

Speed ➵

We ran along with Mongoose, and overtook him in all the races!

| Test | Just-Mongo 2 | Mongoose | |:-----|:----:| :-------:| | Connection | 4 | 46 | | Insert (5k docs) | 366 | 3686 | | Find | 6 | 10 |

...time in ms.

All tests are in directory: test/speed-test.

Feature compatibility

Just-Mongo 2 has new possibilities of mongodb. Please, note this:

  • https://docs.mongodb.com/manual/reference/command/setFeatureCompatibilityVersion/

  • https://docs.mongodb.com/manual/core/schema-validation/#json-schema

Switching from v1.x

The following should be know when upgrading version:

  • Better, update old models to new json schemes.
  • Old models will work in limited functionality. Stop working: isValid.

Install

$ npm i just-mongo -S

Tests

$ npm test

Docs

Create models

Limited version:

const models = {
  users: {
    name: {
      type: String,
    },
    age: Number,
    id: {
      type: Number,
      required: true
    },
    ban: {
      type: Boolean,
      default: false
    }
  }
};

Flexible version:

const models = {
  users: {
    $jsonSchema: {
      bsonType: 'object',
      properties: {
        name: {
          type: 'string'
        },
        age: {
          type: 'number'
        },
        id: {
          type: 'number'
        },
        ban: {
          type: 'boolean',
          default: false
        }
      },
      required: ['name', 'id']
    }
  }
};

The default values are not supported by the database itself, the values are set before creating the records. Do not use the default values in schemes in allOf, anyOf, oneOf, .etc.

Create connection

| Parameter | Type | Requried | Default | |:----------|:----:| :-------:| :------:| | models | object | no | - | | log | false, true, error, warn, info, verbose, debug, silly | no | false | | db | string | yes | '' | | host | string | no | localhost | | user | string | no | '' | | password | string | no | '' | | port | number/string | no | 27017 |

  • log — Set the logging.
import JustMongo from 'just-mongo'
// const JustMongo = require('just-mongo').default;

const mongo = new JustMongo({
  models,
  db: 'database'
}, (err, done) => {
  if (err) {
    console.error(err)
  } else {
    console.log(done)
  }
});

If you need create multi connections, read this doc.

Collection

const Users = mongo.collection('users');

Collection [native]

const Users = mongo.collection('users').collection;

Such a method should be used if you are sure that there is already a connection to the MongoBD. If there is no such certainty, then use the method described below.

const Users = mongo.collection('users');

await Users.native((collection, resolve, reject) => {
  // use collection.MethodFromNative
  // сomplete the function using resolve or reject
});

This method will be executed after connecting to the database. After that, you can use the first method.

Insert

| Parameter | Type | Requried | Default | |:----------|:----:| :-------:| :------:| | document | object/list<object> | yes | - | | options | object | no | null |

// insert one document
await Users.insert({ user_id: 1 }, { serializeFunctions: true });
// insert several documents
await Users.insert([
  { user_id: 1 }, 
  { user_id: 2 }
]);

Update

| Parameter | Type | Requried | Default | |:----------|:----:| :-------:| :------:| | filter | object | yes | - | | document | object | yes | - | | options | object | no | null |

await Users.updateOne({ user_id: 1 }, {
  $set: {
    first_name: 'Mikhail'
  }
}, { serializeFunctions: false });

await Users.updateMany({ first_name: 'Mikhail' }, {
  $set: {
    age: 15
  }
}, { w: 1 });

Or use methods editOne and editMany to avoid specifying $set for each request.

Delete

| Parameter | Type | Requried | Default | |:----------|:----:| :-------:| :------:| | filter | object | yes | - | | options | object | no | null |

await Users.deleteOne({ first_name: 'Anton' }, { w: 1 });
await Users.deleteMany({ age: 10 }, { wtimeout: 25 });

Find/Count

| Parameter | Type | Requried | Default | |:----------|:----:| :-------:| :------:| | filter | object | yes | - | | options | object | no | null |

const item = await Users.findOne({ age: 15 }, { limit: 5 });
const items = await Users.find({});
const itemsCount = await Users.count({ age: 15 }, { maxTimeMS: 2500 });

You can configure additional logic for the contents of documents.

Searching for random entries

| Parameter | Type | Requried | Default | |:----------|:----:| :-------:| :------:| | filter | object | no | null | | count | number | no | 5 | | options | object | no | null |

Options:

  • project — control the display of fields as a result.
const items = await Users.findRandom({ age: 25 }, 2, {
  project: {
    id: 1,
    name: 1,
    _id: 0
  }
});

Getting updates

To constantly receive new data from one or more collections at once, you can use our listening solution. Open doc.

Join engine

If you need joined collection, use join engine.


There's some cool examples too.


Native connections

In case you need to create your own flexible connection using mongodb native, read this doc.

License

MIT.