Giter Site home page Giter Site logo

pk_mongo's Introduction

pk_mongo

Mongo Helper Library

This is a very simple promise based library intended to write queries efficiently in nodejs if you are using mongodb as database.

The idealogies which were kept in mind are:

  • Simple and light library
  • Easy to use

API Documentation

create

MongoHelper.create(collectionName<String>, data<Object>)
This function is used to insert a record into the given collection.
It takes two arguments, the first being the collection name and the second being the data to be inserted.

update

MongoHelper.update(collectionName<String>, criteria<Object>, dataToUpdate<Object>)
This function is used to update a record in a given collection based on certain criteria.
It takes three arguments, the first being the collection name and the second being conditional criteria and the third being the data to be inserted.

findOneByCriteria

MongoHelper.findOneByCriteria(collectionName, criteria<Object>)
This function is used to find a particular record based on a criteria.
It takes two arguments, the first being the collection name and the second being the conditional criteria. It returns only one record.

findByCriteria

MongoHelper.findByCriteria(collectionName<String>, criteria<Object>)
This function is used to find some records based on a criteria.
It takes two arguments, the first being the collection name and the second being the conditional criteria. It returns more than one record if available.

deleteByCriteria

MongoHelper.deleteByCriteria(collectionName<String>, criteria<Object>)
This function is used to delete a record based on some criteria.
It takes two arguments, the first being the collection name and the second being the conditional criteria. It deletes only one record

findAndProject

MongoHelper.findAndProject(collectionName<String>, criteria<Object>, projectionFields[Array])
This function is used to find records based on certain criteria and project specific fields in the result set.
It takes three arguments, the first being the collection name, the second being the conditional criteria and the third being the fields which you want to be projected in the resultset. It returns more than one record if available.

findCountByCriteria

MongoHelper.findCountByCriteria(collectionName<String>, criteria<Object>)
This function is used to calculate the count of records based on certain search criteria.
It takes two arguments, the first being the collection name and the second being the conditional criteria. It returns the count of the result set.

addToSet

MongoHelper.addToSet(collectionName<String>, criteria<Object>, fieldName<String>, valueToAdd<Any>
This function is to push a value to an array of values of a particular field in the collection.
It takes four arguments, the first being the collection name, the second being the conditional criteria, the third being the field name where you have to push the value and the fourth being the value to be pushed.

pullFromSet

MongoHelper.pullFromSet(collectionName<String>, criteria<Object>, fieldName<String>, valueToRemove<Any>
This function is to delete/pull a value from an array of values of a particular field in the collection.
It takes four arguments, the first being the collection name, the second being the conditional criteria, the third being the field name where you want the value to be deleted and fourth being the value to be pulled/deleted.

incrementField

MongoHelper.incrementField(collectionName<String>, criteria<Object>,fieldToIncrement<String>)
This function is used to increment the value of a particular field by 1 in a given collection based on certain criteria
It takes three arguments, the first being the collection name and the second being the conditional criteria and the third being the field which needs to be incremented.

decrementField

MongoHelper.decrementField(collectionName<String>, criteria<Object>,fieldToIncrement<String>)
This function is used to decrement the value of a particular field by 1 in a given collection based on certain criteria
It takes three arguments, the first being the collection name and the second being the conditional criteria and the third being the field which needs to be decremented.

pk_mongo's People

Contributors

pankaj805 avatar

Watchers

James Cloos avatar Aritra avatar

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.