Mongoose: マングースで `--authenticationDatabase`を指定するにはどうすればよいですか?

作成日 2016年02月23日  ·  6コメント  ·  ソース: Automattic/mongoose

シェルで動作します:

$ mongo -u monguser -p mongpass 192.168.2.2/ps --authenticationDatabase=admin
MongoDB shell version: 3.2.3
connecting to: 192.168.2.2/ps
Server has startup warnings: 
2016-02-23T01:59:10.522+0000 I CONTROL  [initandlisten] 
2016-02-23T01:59:10.522+0000 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
2016-02-23T01:59:10.522+0000 I CONTROL  [initandlisten] **        We suggest setting it to 'never'
2016-02-23T01:59:10.522+0000 I CONTROL  [initandlisten] 
2016-02-23T01:59:10.522+0000 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
2016-02-23T01:59:10.522+0000 I CONTROL  [initandlisten] **        We suggest setting it to 'never'
2016-02-23T01:59:10.522+0000 I CONTROL  [initandlisten] 
> db.foo.insert({can:'haz'})
WriteResult({ "nInserted" : 1 })

マングースで失敗する:

'use strict';

const mongoose = require('mongoose');

const uri = 'mongodb://monguser:[email protected]:27017/ps'

console.log('mongoose.connect =', mongoose.connect(uri, (err) => {
    err && console.log('err =', err);
}));
// For `mongoose.connect` output, see: https://gist.github.com/SamuelMarks/dedd863742f90cf2f333
err = { [MongoError: Authentication failed.]
  name: 'MongoError',
  message: 'Authentication failed.',
  ok: 0,
  code: 18,
  errmsg: 'Authentication failed.' }

したがって、 authenticationDatabaseを何らかの方法で、おそらくconfigパラメーターで設定する必要があると想定するのは簡単です。 _構文は何ですか?_

最も参考になるコメント

最も簡単な方法は、URIでauthSourceを指定することです

const uri = 'mongodb://monguser:[email protected]:27017/ps?authSource=admin';

全てのコメント6件

最も簡単な方法は、URIでauthSourceを指定することです

const uri = 'mongodb://monguser:[email protected]:27017/ps?authSource=admin';

mongodb接続文字列のドキュメントを参照してください

ありがとう

@ vkarpov15あなたは私の日を救った。 どうもありがとう。

mongodumpコマンドを使用するときにauthSourceを指定する方法を知っている人はいますか? :]

@ORESoftware mongodumpはそれをauthenticationDatabaseと呼びます: https ://docs.mongodb.com/manual/reference/program/mongodump/#cmdoption -authenticationdatabase

このページは役に立ちましたか?
0 / 5 - 0 評価