MongoDB Atlas 인스턴스를 보유하고 있으며 연결할 수 있지만 계정을 만들고 node.js에서 DB에 액세스 할 수 없습니다. &> 'use mytestcollection'아래의 mongo 명령을 사용한 후 Mongo Shell에서 DB에 액세스 할 수 있습니다. 셸에서 직접 내 testcollection에 액세스하려고하면 '오류 인증 실패'가 반환됩니다.node.js를 사용하여 MongoDB Atlas 사용자 인증
Here'e 쉘 연결 문자열 .. 여기
mongo mongodb://<atlasDB>-1-shard-00-00-<string>.mongodb.net:27017,<atlasDB>-1-shard-00-01-<string>.mongodb.net:27017,<atlasDB>-1-shard-00-02-<string>.mongodb.net:27017/admin?replicaSet=<atlasDB>-1-shard-0 --ssl --username <account> --password <password>
는 Node.js를 코드
var uri = "mongodb://<atlasDB>-1-shard-00-00-<string>.mongodb.net:27017,"+
"<atlasDB>-1-shard-00-01-<string>.mongodb.net:27017,"+
"<atlasDB>-1-shard-00-02-<string>.mongodb.net:27017/mytestcollection?"+
"replicaSet=-1-shard-0"+
"&ssl=true"+
"&authSource=<admin>"+
"&username=<account>"+
"&password=<password>"
및 노드 코드가있어 ...
MongoDB.connect(uri,function(e,db) {
if (e) { console.error('Mongo Failed'); return console.log(e); }
console.log('MongoSuccess');
db.collection('mytestcollection').find().toArray(function(e,d) {
if (e) { console.log('error'); console.log(e); }
if (d) { console.log('test.length',d.length); }
});
});
그리고 오류는 ...
MongoSuccess
error
{ MongoError: not authorized on test to execute command { find: "mytestcollection", filter: {} }
at Function.MongoError.create (/home/ec2-user/frame/node_modules/mongodb-core/lib/error.js:31:11)
at queryCallback (/home/ec2-user/frame/node_modules/mongodb-core/lib/cursor.js:206:36)
at /home/ec2-user/frame/node_modules/mongodb-core/lib/connection/pool.js:430:18
at _combinedTickCallback (internal/process/next_tick.js:67:7)
at process._tickCallback (internal/process/next_tick.js:98:9)
name: 'MongoError',
message: 'not authorized on test to execute command { find: "mytestcollection", filter: {} }',
ok: 0,
errmsg: 'not authorized on test to execute command { find: "mytestcollection", filter: {} }',
code: 13 }
제안 사항을 환영합니다.