//the first user
{
    "_id" : "admin.guguji55",
    "user" : "guguji55",
    "db" : "admin",
    "roles" : [
        {
            "role" : "readWrite",
            "db" : "test"
        }
    ]
}

//the second user
{
    "_id" : "test.guguji66",
    "user" : "guguji66",
    "db" : "test",
    "roles" : [
        {
            "role" : "readWrite",
            "db" : "test"
        }
    ]
}


我创建了两个用户,'guguji55'无法连接我的测试数据库,但是'guguji66'可以连接。我不知道为什么。我的nodejs连接代码如下:

MongoClient.connect('mongodb://guguji66:du****kuan****@localhost:27017/test', function(err, db) {});

最佳答案

 //the first user
    {
        "_id" : "admin.guguji55",
        "user" : "guguji55",
        "db" : "admin",
        "roles" : [
                {
                        "role" : "readWrite",
                        "db" : "test"
                }
        ]
}
 //the second user
{
        "_id" : "test.guguji66",
        "user" : "guguji66",
        "db" : "test",
        "roles" : [
                {
                        "role" : "readWrite",
                        "db" : "test"
                }
        ]
}


参考上面的块,您为admin数据库创建了第一个用户(guguji55)。第二个用户(guguji66)用于测试数据库。
您试图将测试数据库与您无法连接的第一个用户连接。

关于node.js - 任何人都可以在mongodb3.4.5中解释两个用户之间的区别,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/45778668/

10-11 14:05