Fonctionne dans le shell :
$ 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 })
Échec dans la mangouste :
'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.' }
Il est donc prudent de supposer que authenticationDatabase
doit être défini d'une manière ou d'une autre, peut-être dans le paramètre de configuration. _Quelle est la syntaxe ?_
Le moyen le plus simple est de spécifier authSource
dans l'uri
const uri = 'mongodb://monguser:[email protected]:27017/ps?authSource=admin';
Merci
@vkarpov15 tu as sauvé ma journée. Merci beaucoup.
Quelqu'un sait-il comment spécifier authSource lors de l'utilisation de la commande mongodump ? :]
@ORESoftware mongodump l'appelle authenticationDatabase
: https://docs.mongodb.com/manual/reference/program/mongodump/#cmdoption -authenticationdatabase
Commentaire le plus utile
Le moyen le plus simple est de spécifier
authSource
dans l'uriconst uri = 'mongodb://monguser:[email protected]:27017/ps?authSource=admin';