GithubHelp home page GithubHelp logo

mongodash's Introduction


Mongodash

A modern JavaScript & Typescript MongoDB-based utility library allowing to develop common app requirements incredible simple.

Coverage Status Mutation testing badge Types

See full documentation on http://mongodash.com



Installation:

npm install mongodash

Initialization

const mongodash = require('mongodash');

await mongodash.init({
    uri: 'mongodb://mongodb0.example.com:27017/myDatabase' 
});

See more initialization options here.


cronTask

const { cronTask } = require('mongodash');

await cronTask('my-task-id', '5m 20s', async () => {
  
    console.log('Hurray the task is running!');

});

See detailed description and more cron tasks methods here.


withLock

const { withLock } from 'mongodash';

await withLock('my-lock-id', async () => {
  
  // it is quaranteed this callback will never run in parallel, 
  // so all race-conditions are solved
  const data = await loadFromDatabase();
  data.counter += 1;
  await saveToDatabase(data);
  
});

See detailed description here.


withTransaction

const { withTransaction, getCollection } = require('mongodash');

const createdDocuments = await withTransaction(async (session) => {
    
  const myDocument1 = { value: 1 };
  const myDocument2 = { value: 2 };
  
  const collection = getCollection('myCollection');
  await testCollection.insertOne(myDocument1, { session });
  await testCollection.insertOne(myDocument2, { session });
  
  return [myDocument1, myDocument2];
});

See detailed description here.


getCollection

const { getCollection } = require('mongodash');

const myCollection = getCollection('myCollectionName');

See detailed description here.


getMongoClient

const { getMongoClient } = require('mongodash');

const mongoClient = getMongoClient();

See detailed description here.

mongodash's People

Contributors

dependabot[bot] avatar semantic-release-bot avatar vaclavobornik avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

mongodash's Issues

Allow reinit

Hello,

How can I reinit mongodash after I closed a previous connection ?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.