// Add mongoose
import mongoose from 'mongoose';
// Not Working
mongoose.connect('mongodb://localhost/playground')
.then(() => console.log(MongoDB Connected...
))
.catch(err => console.log(Error ${err}
))
// Working
mongoose.connect('mongodb://localhost:27017/playground')
.then(() => console.log(MongoDB Connected...
))
.catch(err => console.log(Error ${err}
))
MongoDB 3.1 deprecated the old url parsing. By passing useNewUrlParser
you must supply a port number
@dbellvista For the past few days I’ve been working on a basic REST API using MongoDB 4.0.0 and Mongoose 5.1.? and not passing the specific port and it’s worked fine. As soon as 5.2.0 came out I’ve now had to start passing my port. If I have to continue doing this in the future that’s perfectly fine, but I’m not exactly sure that it was deprecated with 3.1 as I’ve been using 4. Thank you for the info!!
Still I think it's a mongodb bug, since the default port should be 27017. I opened a bug in mongo (https://jira.mongodb.org/browse/NODE-1547).
(and I messed up the title, I hope they won't close it as invalid...)
Same here.
Updated from 5.1.5 to 5.2.0, exactly this problem started. Downgraded to 5.1.5 it is working again
Also have address as this mongodb://localhost/playground
Full error log
"stack": "MongoError: port must be specified\n at Function.MongoError.create (/usr/src/app/node_modules/mongodb-core/lib/error.js:49:10)\n at new Server (/usr/src/app/node_modules/mongodb/lib/topologies/server.js:136:24)\n at options.servers.map.serverObj (/usr/src/app/node_modules/mongodb/lib/operations/mongo_client_ops.js:570:9)\n at Array.map (<anonymous>)\n at translateOptions (/usr/src/app/node_modules/mongodb/lib/operations/mongo_client_ops.js:567:26)\n at createServer (/usr/src/app/node_modules/mongodb/lib/operations/mongo_client_ops.js:332:19)\n at parseFn (/usr/src/app/node_modules/mongodb/lib/operations/mongo_client_ops.js:221:14)\n at parseConnectionString (/usr/src/app/node_modules/mongodb-core/lib/uri_parser.js:307:3)\n at connect (/usr/src/app/node_modules/mongodb/lib/operations/mongo_client_ops.js:179:3)\n at connectOp (/usr/src/app/node_modules/mongodb/lib/operations/mongo_client_ops.js:283:3)\n at executeOperation (/usr/src/app/node_modules/mongodb/lib/utils.js:420:24)\n at MongoClient.connect (/usr/src/app/node_modules/mongodb/lib/mongo_client.js:168:10)\n at MongoClient.connect (/usr/src/app/node_modules/mongodb/lib/apm.js:20:32)\n at Promise (/usr/src/app/node_modules/mongoose/lib/connection.js:455:12)\n at new Promise (<anonymous>)\n at NativeConnection.Connection.openUri (/usr/src/app/node_modules/mongoose/lib/connection.js:452:19)"
@dbellavista is correct. The underlying driver requires the port when using the new url parser option which mongoose 5.2 does. This isn't the only issue with the new url parser. I've created a PR to set useNewUrlParser to false for the time being until the driver is updated #6652.
@LiborVilimekMassive Yeah I really hope they fix this issue, it’s not a huge deal to specify the port but as far as consistency it’s much easier for development.
@Kev however setting the flag to false triggers a nodejs warning
On Tue, 3 Jul 2018, 15:36 SZun, notifications@github.com wrote:
@LiborVilimekMassive https://github.com/LiborVilimekMassive Yeah I
really hope they fix this issue, it’s not a huge deal to specify the port
but as far as consistency it’s much easier for development.—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/Automattic/mongoose/issues/6647#issuecomment-402159604,
or mute the thread
https://github.com/notifications/unsubscribe-auth/ABeA4UNxK5Pdzj9iKnNAAa4Cy65OUBNEks5uC3NrgaJpZM4VAV8u
.
@dbellavista, I noted the deprecation warnings in my PR. Personally, a deprecation warning seems better to me than the alternatives of either waiting for the driver to get updated & published or everyone having to specify the port, or move bits of their connection options from the uri to the options object as shown in other issues.
Thanks for reporting, will fix ASAP.
Most helpful comment
Still I think it's a mongodb bug, since the default port should be 27017. I opened a bug in mongo (https://jira.mongodb.org/browse/NODE-1547).
(and I messed up the title, I hope they won't close it as invalid...)