Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including mongo-wrapper-pooled with all npm packages installed. Try it out:

var mongoWrapperPooled = require("mongo-wrapper-pooled")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

mongo-wrapper-pooled v0.0.2

A wrapper library around mongodb with connection pooling using generic-pool

Build Status mongo-wrapper-pooled ====================

A wrapper library around mongodb with connection pooling using generic-pool

Usage

Initialise

var MongoWrapper = require('mongo-wrapper-pooled');
var settings = {
        host: 'localhost',
        port: '27017',
        db: 'testDb',
        maxPoolSize : 1,
        minPoolSize : 0,
        idleTimeoutMillis: 30000,
    };
var instance = new MongoWrapper( settings );

instance.findOne('collectionName', {userId: 'hari'}, console.log );
instance.findOne('collectionName', {userId: 'hari'}, { email: false}, console.log );
instance.find('collectionName', {active: True, $limit:20}, { email: false}, console.log );
// In general, instance.<CollectionMethod>( <CollectionName>, args... );

Implemented methods

All methods available to a Mongodb Collection is implemented. For the convenience, the following methods do some more things

  • find: It returns an array instead of a databse cursor. array is the result of cursor.toArray(); If any of '$limit', '$sort', '$skip', '$fields' keys are present in the second argument, it is passed as argument to functions 'limit()', 'sort()', 'skip()', 'fields()' respectively before calling cursor.toArray().

Metadata

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free