"?" in connection string fails but doesn't throw an error #460

Closed
mypark opened this Issue Aug 14, 2011 · 2 comments

Comments

Projects
None yet
3 participants

mypark commented Aug 14, 2011

new to mongoose, express and mongo so not sure where this issue lies, but when using a connection string with a "?" in the password, e.g.

"mongodb://myuser:mypwd?@dbh.mongohq.com:1234/mydb";

I don't get an error but it just hangs when making a query. Should the password be url encoded? Why don't I get a connection failed error?

sample code:

var ObjectId, Profile, ProfileSchema, Schema, app, connStr, db, express, mongoose;
express = require("express");
app = module.exports = express.createServer();
mongoose = require("mongoose");
connStr = "mongodb://myuser:mypwd?@dbh.mongolab.com:1234/mydb";
db = mongoose.connect(connStr);

...

app.get('/test', function(req, res) {
console.log("test requested");
Profile.findOne({
"name": "MyName"
}, function(err, profile) {
if (!err) {
return res.send(profile);
} else {
return console.log("error requesting profile");
}
});
});

I had a similar problem, my password contained special characters and I didn't realize that was causing it to fail. Mongoose uses Node's url.parse on the href you pass in and will incorrectly parse certain special characters.

The node-mongodb-native driver currently has a pull-request to automatically encode username/passwords passed in, Mongoose should consider a similar action.

On second thought, this seems like a non-issue. Encoded special characters in the auth section of a uri would probably get really messy and if anything should be dealt with by the "url" module in node. Someone who know's more may want to comment and close this issue.

aheckmann closed this in 4070747 Jul 16, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment