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

mongoat

Package Overview
Dependencies
Maintainers
1
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mongoat

Mongoat is a MongoDb ODM

  • 1.0.5
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
4
decreased by-71.43%
Maintainers
1
Weekly downloads
 
Created
Source

Mongoat

Codacy Badge Codacy Badge dev dependencies

mongoat gif

Description

Mongoat is a MongoDB ODM. It is written on top of the mongodb npm package to add new features.

Documentation

Because Mongoat is written on top of the mongodb native driver, you can find more about here

Features

  • Hooks
  • Enabling datetime (createdAt & updatedAt)
  • Transparent usage (raw access to native MongoDB driver)
  • Versioning of documents
  • Oplogs events (not yet)

Installation

 $> npm install mongodm

Basic usage

var mongoat = require('mongoat');
var url = 'mongodb://localhost:27017/myproject'; // Connection URL

mongoat.MongoClient.connect(url)
.then(function (db) {
    // then use it the same way as native mongodb driver
});

Hooks

You can add multiple before and after hooks for insertions, updates and removals:

before hooks:

db.collection('collectionName').before('insert', function (docToInsert) {
  // triggered when calling to insert()
});

db.collection('collectionName').before('update', function (docToUpdate) {
  // triggered when calling to update() or findAndModify()
});

db.collection('collectionName').before('remove', function (docToRemove) {
  // triggered when calling to remove()
}); 

after hooks:

db.collection('collectionName').after('insert', function (docToInsert) {
  // triggered when calling to insert()
});

db.collection('collectionName').after('update', function (docToUpdate) {
  // triggered when calling to update() or findAndModify()
});

db.collection('collectionName').after('remove', function (docToRemove) {
  // triggered when calling to remove()
}); 

Datetime

Enable datetime feature:

    db.collection('collectionName').datetime(true); // Default is false

createdAt:

it will add a createdAt field to all new inserted documents using:

db.collection('collectionName').insert(document, options);

or using one of the following method within the option upsert: ture

db.collection('collectionName').update(query, update, options);
db.collection('collectionName').findAndModify(query, sort, update, options);

updatedAt:

it will add a updatedAt field to all updated documents using:

db.collection('collectionName').update(query, update, options);
// or
db.collection('collectionName').findAndModify(query, sort, update, options);

Versioning

Enable versioning feature:

    db.collection('collectionName').version(true); // Default is false

Enabling this feature for a collection, so each time you perform an insert/update/remove it will create a document in the collection collectionName.vermongo and increment the version of the updated document. The _id in this collection is a composite ID, { _id: _id, _version: _version }. The document in the MyCollection collection will also receive a _version field.

If we want to restore a version

    db.collection('collectionName').restore(version); // Default is false
  • if version is greater than 0, it will be considered as the version to restore
  • if version is equal or lower than 0, it will be considered as the starting point of the version to restore (starting form last) ex:
    db.collection('collectionName').restore(0); // restore the last version
    db.collection('collectionName').restore(-2); // restore the last version -2

more about versioning feature here

Tests

  1. Run a MongoDb server if not yet
  2. Run tests npm test

Or to show up code coverage npm run cover it will generate ./coverage folder

Contribution

Please read our Contributing Guidlines before submitting a pull request or an issue !

License

The MIT License MIT

Copyright (c) 2015 Dial Once

Keywords

FAQs

Package last updated on 10 Nov 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

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