redux-persist-mongodb-storage

1.0.2 • Public • Published

Redux Persist MongoDb Storage

This is an object to be used with redux-persist. It conforms to the current storage object definition in that it has the following methods exposed:

getItem(key)
setItem(key, value)
removeItem(key)

The intent is for this to provide a server side storage object that uses MongoDb as the backing store.

Usage

First install the store using npm, eg:

npm install - S redux-persist-mongodb-storage

Then in your code include the store, for example in store.js:

import { createStore } from 'redux';
import { persistStore, persistReducer} from 'redux-persist';
import MongoDBStore from 'redux-persist-mongodb-storage';
import reducer from '../reducers';

export default function makeStore() {

    const persistConfig = {
  		key: 'root',
  		storage: MongoDBStore
        }

    const persistedReducer = persistReducer(persistConfig, reducer);

    let store = createStore(persistedReducer);
    let persistor = persistStore(store);

    return { store, persistor };
    }

In order to supply a custom configuration you can do something like the following:

var options = {
    name:			'testdb',
    collection:		'stuff'
    }

MongoDBStore.configure(options);

const persistConfig = {
    key: 'root',
    storage: MongoDBStore
    }

Configuring MongoDb

To configure this object to work with MongoDb pass a configuration object to the configure method. The configuration values are in the table below with their defaults:

Config Default Description
url mongodb://localhost/ The url used to connect to MongoDb upon. This conforms the the MongoDb URL documentation.
connect_opts {} Connection options passed tot he connect method call. These conform to the connection options used by the MongoClient.
name redux-db The name of the MongoDb database used.
collection state-collection The name of the document collection used in the database.

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 1.0.2
    1
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 1.0.2
    1
  • 1.0.1
    0

Package Sidebar

Install

npm i redux-persist-mongodb-storage

Weekly Downloads

1

Version

1.0.2

License

MIT

Unpacked Size

8.45 kB

Total Files

5

Last publish

Collaborators

  • nigel-daniels