如何在 auth0 中添加 mongodb 数据库连接 url?
How to add mongodb db connection url in auth0?
我在使用 auth0 自定义数据库连接时遇到一些问题。
这是代码(它是 auth0 模板):
function create (user, callback) {
mongo('mongodb://user:pass@mymongoserver.com/my-db', function (db) {
var users = db.collection('users');
users.findOne({ email: user.email }, function (err, withSameMail) {
if (err) return callback(err);
if (withSameMail) return callback(new Error('the user already exists'));
bcrypt.hash(user.password, 10, function (err, hash) {
if (err) { return callback(err); }
user.password = hash;
users.insert(user, function (err, inserted) {
if (err) return callback(err);
callback(null);
});
});
});
});
}
我使用 MongoDB Atlas 作为数据库,但我不知道如何将此数据库连接到 auth0,因为当我尝试像这样放置 Atlas url
"mongodb://kay:myRealPassword@mycluster0-shard-00-00.mongodb.net:27017,mycluster0-shard-00-01.mongodb.net:27017,mycluster0-shard-00-02.mongodb.net:27017/admin?ssl=true&replicaSet=Mycluster0-shard-0&authSource=admin"
Auth0 抛出这个错误:
[Error] Error: Client request error: socket hang up
at createHangUpError (_http_client.js:213:15)
at Socket.socketOnEnd (_http_client.js:305:23)
at emitNone (events.js:72:20)
at Socket.emit (events.js:166:7)
at endReadableNT (_stream_readable.js:923:12)
at nextTickCallbackWith2Args (node.js:511:9)
at process._tickDomainCallback (node.js:466:17)
当我像这样使用 url 时:
mongodb+srv://kay:myRealPassword@cluster0.mongodb.net/test
它给我这样的东西:
[SandboxUnhandledError] unknown mongodb+srv://kay:myRealPassword@cluster0.mongodb.net/test config
请帮助我,因为我不知道该怎么做。
P.S。我将 auth0 IP 地址添加到 MongoDB Atlas 白名单。
披露,我为 Auth0 工作。
我认为这可能是旧版驱动程序的问题。 mongo
中的全局当前用于保留遗留脚本。您的新规则/自定义数据库应该 require
一个明确版本的 mongo
驱动程序并依赖它。比如
var mongo = require('mongo');
或者更明确地说
var mongo = require('mongo@x.y.z');
规则/自定义数据库脚本中所有可用模块的完整列表位于 https://tehsis.github.io/webtaskio-canirequire/
我在使用 auth0 自定义数据库连接时遇到一些问题。 这是代码(它是 auth0 模板):
function create (user, callback) {
mongo('mongodb://user:pass@mymongoserver.com/my-db', function (db) {
var users = db.collection('users');
users.findOne({ email: user.email }, function (err, withSameMail) {
if (err) return callback(err);
if (withSameMail) return callback(new Error('the user already exists'));
bcrypt.hash(user.password, 10, function (err, hash) {
if (err) { return callback(err); }
user.password = hash;
users.insert(user, function (err, inserted) {
if (err) return callback(err);
callback(null);
});
});
});
});
}
我使用 MongoDB Atlas 作为数据库,但我不知道如何将此数据库连接到 auth0,因为当我尝试像这样放置 Atlas url
"mongodb://kay:myRealPassword@mycluster0-shard-00-00.mongodb.net:27017,mycluster0-shard-00-01.mongodb.net:27017,mycluster0-shard-00-02.mongodb.net:27017/admin?ssl=true&replicaSet=Mycluster0-shard-0&authSource=admin"
Auth0 抛出这个错误:
[Error] Error: Client request error: socket hang up
at createHangUpError (_http_client.js:213:15)
at Socket.socketOnEnd (_http_client.js:305:23)
at emitNone (events.js:72:20)
at Socket.emit (events.js:166:7)
at endReadableNT (_stream_readable.js:923:12)
at nextTickCallbackWith2Args (node.js:511:9)
at process._tickDomainCallback (node.js:466:17)
当我像这样使用 url 时:
mongodb+srv://kay:myRealPassword@cluster0.mongodb.net/test
它给我这样的东西:
[SandboxUnhandledError] unknown mongodb+srv://kay:myRealPassword@cluster0.mongodb.net/test config
请帮助我,因为我不知道该怎么做。 P.S。我将 auth0 IP 地址添加到 MongoDB Atlas 白名单。
披露,我为 Auth0 工作。
我认为这可能是旧版驱动程序的问题。 mongo
中的全局当前用于保留遗留脚本。您的新规则/自定义数据库应该 require
一个明确版本的 mongo
驱动程序并依赖它。比如
var mongo = require('mongo');
或者更明确地说
var mongo = require('mongo@x.y.z');
规则/自定义数据库脚本中所有可用模块的完整列表位于 https://tehsis.github.io/webtaskio-canirequire/