Coder Social home page Coder Social logo

mongo-query-helper's Introduction

mongo-query-helper Build Status

Mongo query helper for common, repetitive queries. Easier to write and saves some typing.

Install

$ npm install mongo-query-helper

Usage

const mh = require('mongo-query-helper');

//mongoose
User.find({accessLevel: mh.ne(2)}, function(err, users){
    if(!err){
        console.log(users)
    }
});

Match.find({completed: mh.exists(), score: mh.gtLt(32, 100)}, function(err, matches){
    if(!err){
        console.log(matches)
    }
});

APIs

lt(param)

Less than

mh.lt(2)
// { '$lt': 2}

lte(param)

Less than equal to

mh.lte(2)
// { '$lte': 2}

gt(param)

Greater than

mh.gt(2)
// { '$gt': 2}

gte(param)

Greater than equal to

mh.gte(2)
// { '$gte': 2}

gtLt(param, param)

Greater than and less than

mh.gtLt(2, 4)
// { '$gt': 2, '$lt': 4}

gteLt(param, param)

Greater than equal to and less than

mh.gteLt(2, 4)
// { '$gte': 2, '$lt': 4}

gtLte(param, param)

Greater than and less than equal to

mh.gtLte(2, 4)
// { '$gt': 2, '$lte': 4}

gteLte(param, param)

Greater than equal to and less than equal to

mh.gteLte(2, 4)
// { '$gte': 2, '$lte': 4}

exists()

mh.exists()
// { '$exists': true}

notExists()

mh.notExists()
// { '$exists': false}

eq(param)

Equal to

mh.eq(7)
// { '$eq': 7}

ne(param)

Not equal to

mh.ne(7)
// { '$ne': 7}

in([params] | param, param)

mh.in([1, 2, 3])
// OR
mh.in(1, 2, 3)
// { '$in': [1, 2, 3]}

nin([params] | param, param)

Not in

mh.nin([1, 2, 3])
// OR
mh.nin(1, 2, 3)
// { '$nin': [1, 2, 3]}

mod(param, param)

Modulo

mh.mod(4, 0)
// { '$mod': [4, 0]}

merge(param, param)

Merges all the object parameters into one. Shorter name mrg

mh.mrg(mh.exists(), mh.ne(2), mh.gteLte(1, 10))
// { '$exists': true, '$ne': 2, '$gte': 1, '$lte': 10}

Related

License

MIT © Talha Awan

mongo-query-helper's People

Contributors

talhaawan avatar

Watchers

 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.