Inspired from i18next-node-mongodb-backend with support for mongodb@3.5.x
, some bug fixes and more improvements
This is a i18next backend to be used node.js. It will load resources from a MongoDB database with official node mongodb driver.
npm install mongodb i18next-node-mongo-backend
# or
yarn add mongodb i18next-node-mongo-backend
Important: This library doesn't include
mongodb
library. You have to install it yourself
const i18next = require('i18next');
const Backend = require('i18next-node-mongo-backend');
i18next.use(Backend).init({
// Backend Options
backend: options
});
{
// If you have your own MongoClient, put in here:
// Note: If this has already been entered, the other MongoDB standard configurations will be ignored
client: new MongoClient(), // work with connected client or not
// Or (Choose one)
// MongoDB standard configuration
host: '127.0.0.1',
port: 27017,
dbName: '<DB Name>',
// MongoDB authentication. Remove it if not needed
user: '<User>',
password: '<Password>',
// Collection name in database will be used to store i18next data
collectionName: 'i18n',
// MongoDB field name
languageFieldName: 'lang',
namespaceFieldName: 'ns',
dataFieldName: 'data',
// Error handlers
readErrorHandler: console.error,
readMultiErrorHandler: console.error,
createErrorHandler: console.error,
// MongoClient Options. See https://mongodb.github.io/node-mongodb-native/3.5/api/MongoClient.html
mongodb: {
auto_reconnect: true,
useUnifiedTopology: true
}
};
We do not provide
uri
options. You just fill out the available options, we will do it automatically for you