Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js Mongoose验证失败`_Node.js_Mongodb_Ssl_Mongoose - Fatal编程技术网

Node.js Mongoose验证失败`

Node.js Mongoose验证失败`,node.js,mongodb,ssl,mongoose,Node.js,Mongodb,Ssl,Mongoose,我使用的是Mongoose版本:4.3 我可以使用Studio3Tmongo客户端连接到mongoDb。 但在NodeJ内尝试使用Mongoose进行连接时出现身份验证错误 我的代码如下所示: const sslOptions = { server: { sslValidate: false, ssl: true, sslCert: certFileBuf, sslKey: certFileBuf, chec

我使用的是
Mongoose版本:4.3
我可以使用
Studio3T
mongo客户端连接到
mongoDb
。 但在NodeJ内尝试使用
Mongoose
进行连接时出现身份验证错误

我的代码如下所示:

const sslOptions = {
    server: {
        sslValidate: false,
        ssl: true,
        sslCert: certFileBuf,
        sslKey: certFileBuf,
        checkServerIdentity: false,
        sslPass: 'mysslPass',
    },
    user: 'myUser',
    pass: 'myPass'

};
connName = mongoose.createConnection("mongodb://server.com:27017/db1?tls=true&authSource=db1", sslOptions);
上面的错误提示:

mongodb\node_modules\mongoose\node_modules\mongodb\lib\utils.js:98
    process.nextTick(function() { throw err; });
                                  ^
Error [MongoError]: Authentication failed.

在url中设置用户名和密码

connName = mongoose.createConnection("mongodb://myUser:myPass@server.com:27017/db1?tls=true&authSource=db1", {
        sslValidate: false,
        ssl: true,
        sslCert: certFileBuf,
        sslKey: certFileBuf,
        checkServerIdentity: false,
        sslPass: 'mysslPass',
    });