Znaky jako @ jsou omezeny, protože narušují strukturu adresy URL. Důvodem je to, že to MongoDB interpretuje jako oddělovač @. Místo toho:
var mongoClient = require("mongodb").MongoClient;
mongoClient.connect("mongodb://myuser:example@sqldat.com@myhost.documents.azure.com:10355/?ssl=true", function (err, db) {
db.close();
});
použijte toto
mongoClient.connect("mongodb://myuser:myp%example@sqldat.com:10355/?ssl=true", {
uri_decode_auth: true
}, function (err, db) {
db.close();
});
Pro zakódování hesla použijte encodeURIComponent(password)
Můžete také použít tuto syntaxi.
mongoClient.connect("mongodb://myhost.documents.azure.com:10355/?ssl=true",
{user: 'username', pass: 'example@sqldat.com'}, function (err, db) {
db.close();
});
V novějších verzích použijte
auth: {
user: 'username',
password: 'example@sqldat.com',
}
jak je uvedeno níže
mongoClient.connect("mongodb://myhost.documents.azure.com:10355/?ssl=true", {
auth: {
user: 'username',
password: 'example@sqldat.com',
}}, function (err, db) {
db.close();
});