npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

connect-mongo-soajs

v0.2.2

Published

MongoDB session store for Express and Connect with full control over mongo configuration and no race conditions problems - unleashed

Downloads

3

Readme

connect-mongo-soajs

Build Status Coverage Status NPM version

MongoDB session store for Express and Connect

Fed up from not being able to find a decent mongo store with full control over mongo configuration including replica set support and not face a race condition because mongo connections are not being handled the right way.

Connect-mongo-soajs is a store that gives you full control over mongo configuration. Enjoy an unleashed reliable mongo store :)

This is a standanlone version of soajs connect mongo. You can simply use it as a standalone package as described below.

Installation

$ npm install connect-mongo-soajs

Usage

var session = require('express-session');
var MongoStore = require('connect-mongo-soajs')(session);
var store = new MongoStore(dbConfig)

dbConfig

The dbConfig object looks like this:

var dbConfig =  {
    'name' : "",
    'prefix' : "",
    'servers' : [{host : "", port : ""} ...],
    'credentials' : {username : "", password : ""},
    'URLParam' : { },
    'extraParam' : {db : {}, server : {}, replSet : {}, mongos: {}},
    'store': {},
    'collection': "sessions",
    'stringify': false,
    'expireAfter': 1000 * 60 * 60 * 24 * 14 // 2 weeks
}

For a full reference regarding URLParam & extraParam please check out mongodb website

Here is an example of dbConfig object:

var dbConfig = {
    "name": "core_session",
    "prefix": "",
    "servers": [
        {
            "host": "127.0.0.1",
            "port": 27017
        }
    ],
    "credentials": null,
    "URLParam": {
        "maxPoolSize": 5
    },
    "extraParam": {
        "db": {
            "bufferMaxEntries": 0
        }
    },
    'store': {},
    "collection": "sessions",
    'stringify': false,
    'expireAfter': 1000 * 60 * 60 * 24 * 14 // 2 weeks
}

A simple example

var express = require('express');
var session = require('express-session');
var MongoStore = require('connect-mongo-soajs')(session);
var app = express();

var dbConfig = {
    "name": "core_session",
    "prefix": "",
    "servers": [
        {
            "host": "127.0.0.1",
            "port": 27017
        }
    ],
    "credentials": null,
    "URLParam": {
        "maxPoolSize": 5
    },
    "extraParam": {
        "db": {
            "bufferMaxEntries": 0,00
        }
    },
    'store': {},
    "collection": "sessions",
    'stringify': false,
    'expireAfter': 1000 * 60 * 60 * 24 * 14 // 2 weeks
}

var sessionConfig = {
    "name": "soajsID",
    "secret": "this is your session secret shhhhhh",
    "cookie": {"path": '/', "httpOnly": true, "secure": false, "domain": "localhost", "maxAge": null},
    "resave": false,
    "saveUninitialized": false,
    "store" : new MongoStore(dbConfig)
};

app.use(session(sessionConfig));
...

Full reference for URLParam & extraParam

Below is how a configuration object should look like, but Please check out mongodb website

Reference for Mongo Configuration for driver version 2.1

  • Full REF

  • CLIENT REF

  • API REF

  • DB REF

  • REPLICASET REF

  • Setup Mongo + SSL

  • MongoDB NodeJS Driver

     "URLParam": {
         "replicaSet": "rs",                         //name of the replicaSet if mongo connection is not standalone
         "ssl": false,                               //Whether or not the connection requires SSL
         "connectTimeoutMS": 0,                      //connection timeout value in ms or 0 for never
         "socketTimeoutMS": 0,                       //socket timeout value to attempt connection in ms or 0 for never
         "maxPoolSize": 5,                           //pooling value, default=100
         "minPoolSize": 0,                           //todo: not supported by all drivers
    
         "maxIdleTimeMS": 0,                         //todo: Not Supported * The maximum number of milliseconds that a connection can remain idle in the pool before being removed and closed.
         "waitQueueMultiple": 0,                     //todo: Not Supported * A number that the driver multiples the maxPoolSize value to, to provide the maximum number of threads allowed to wait for a connection to become available from the poo
         "waitQueueTimeoutMS": 0,                    //todo: Not Supported * The maximum time in milliseconds that a thread can wait for a connection to become available.
    
         "w": "majority",                            //values majority|number|<tag set>
         "wtimeoutMS": 0,                            //timeout for w, 0 is for never
         "journal": false,                           //Specify a journal write concern.
         "readConcernLevel": "local",
         "readPreference": "secondaryPreferred",     //if ReplicaSet, prefered instance to read from. value=primary|secondary|nearest|primaryPreferred|secondaryPreferred
         "readPreferenceTags": "TAG",
         "authSource": null,                         //specify a db to authenticate the user if the one he is connecting to doesn't do that
         "authMechanism": null,
         "gssapiServiceName": null
     },
     "extraParam": {
         "db": {
             "authSource": null,                         //specify a db to authenticate the user if the one he is connecting to doesn't do that
             "w": "majority",                           //values majority|number|<tag set>
             "wtimeoutMS": 0,                           //timeout for w, 0 is for never
             "j": false,                                //Specify a journal write concern.
             "forceServerObjectId": false,               //Force server to assign _id values instead of driver. default=false
             "serializeFunctions": false,                //Serialize functions on any object. default=false
             "ignoreUndefined": false,                   //Specify if the BSON serializer should ignore undefined fields. default=false
             "raw": false,                               //Return document results as raw BSON buffers. default=false
             "promoteLongs": true,                       //Promotes Long values to number if they fit inside the 53 bits resolution. default=true
             "bufferMaxEntries": -1,                    //Sets a cap on how many operations the driver will buffer up before giving up on getting a working connection, default is -1 which is unlimited.
             "readPreference": "secondaryPreferred",
             "pkFactory": null,                          //A primary key factory object for generation of custom _id keys.
             "promiseLibrary": null,                     //A Promise library class the application wishes to use such as Bluebird, must be ES6 compatible
             "readConcern": null
         },
         "server": {
             "poolSize": 5,
             "ssl": false,
             "sslValidate": true,                       //Validate mongod server certificate against ca, mongod server 2.4 or higher
             "checkServerIdentity": true,               //Ensure we check server identify during SSL, set to false to disable checking
             "sslCA": null,                             //Array of valid certificates either as Buffers or Strings
             "sslCert": null,                           //String or buffer containing the certificate we wish to present
             "sslKey": null,                            //String or buffer containing the certificate private key we wish to present
             "sslPass": null,                           //String or buffer containing the certificate password
             "socketOptions": {
                 "autoReconnect": true,                      //Reconnect on error
                 "noDelay": true,                           //TCP Socket NoDelay option
                 "keepAlive": 0,                             //TCP KeepAlive on the socket with a X ms delay before start
                 "connectTimeoutMS": 0,                      //connection timeout value in ms or 0 for never
                 "socketTimeoutMS": 0                       //socket timeout value to attempt connection in ms or 0 for never
             },
             "reconnectTries": 30,                      //Server attempt to reconnect #times
             "reconnectInterval": 1000,                 //Server will wait # milliseconds between retries
             "monitoring": true,                        //Triggers the server instance to call ismaster
             "haInterval": 10000                        //Time between each replicaset status check
         },
         "replSet": {
             "ha": true,                                //Turn on high availability monitoring.
             "haInterval": 10000,                        //Time between each replicaset status check
             "replicaSet": "rs",
             "secondaryAcceptableLatencyMS": 15,        //Sets the range of servers to pick when using NEAREST
             "connectWithNoPrimary": false,             //Sets if the driver should connect even if no primary is available
             "poolSize": 5,
             "ssl": false,
             "checkServerIdentity": true,               //Ensure we check server identify during SSL, set to false to disable checking
             "sslValidate": true,                       //Validate mongod server certificate against ca, mongod server 2.4 or higher
             "sslCA": null,                             //Array of valid certificates either as Buffers or Strings
             "sslCert": null,                           //String or buffer containing the certificate we wish to present
             "sslKey": null,                            //String or buffer containing the certificate private key we wish to present
             "sslPass": null,                           //String or buffer containing the certificate password
             "socketOptions": {
                 "noDelay": true,                           //TCP Socket NoDelay option
                 "keepAlive": 0,                             //TCP KeepAlive on the socket with a X ms delay before start
                 "connectTimeoutMS": 0,                      //connection timeout value in ms or 0 for never
                 "socketTimeoutMS": 0                       //socket timeout value to attempt connection in ms or 0 for never
             }
         },
         "mongos": {
             "ha": true,                                //Turn on high availability monitoring.
             "haInterval": 10000,                        //Time between each replicaset status check
             "poolSize": 5,
             "acceptableLatencyMS": 15,        //Sets the range of servers to pick when using NEAREST
             "ssl": false,
             "checkServerIdentity": true,               //Ensure we check server identify during SSL, set to false to disable checking
             "sslValidate": true,                       //Validate mongod server certificate against ca, mongod server 2.4 or higher
             "sslCA": null,                             //Array of valid certificates either as Buffers or Strings
             "sslCert": null,                           //String or buffer containing the certificate we wish to present
             "sslKey": null,                            //String or buffer containing the certificate private key we wish to present
             "sslPass": null,                           //String or buffer containing the certificate password
             "socketOptions": {
                 "noDelay": true,                           //TCP Socket NoDelay option
                 "keepAlive": 0,                             //TCP KeepAlive on the socket with a X ms delay before start
                 "connectTimeoutMS": 0,                      //connection timeout value in ms or 0 for never
                 "socketTimeoutMS": 0                       //socket timeout value to attempt connection in ms or 0 for never
             }
         }
     }