任何人都可以在需要MongoDB身份验证时使用i18next-node-mongodb-backend模块。该模块的文档说明如下:
var i18next = require('i18next');
var Backend = require('i18next-node-mongodb-backend');
i18next
.use(Backend)
.init({
backend: options
});我使用了host、port、db和collection选项。但是,是否还可以指定用户和密码?
i18next
.use(mongoBackend)
.use(i18nextMiddleware.LanguageDetector)
.init({
backend: {
host: 'localhost',
port: 27017,
db: 'my_database',
collection: 'my_collection',
// authentication option?谢谢你的回答。
发布于 2018-08-15 19:38:59
通过查看i18next-node-mongodb-backend的代码,我可以确认上面提到的注释。解决此问题的唯一方法是使用uri参数=> https://github.com/gian788/i18next-node-mongodb-backend/blob/master/lib/index.js#L52。
uri应该是这样组成的:https://docs.mongodb.com/manual/reference/connection-string/
mongodb://[username:password@]host1[:port1][,host2[:port2],...[,hostN[:portN]]][/[database][?options]]https://stackoverflow.com/questions/51621806
复制相似问题