Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript User Authentication With Express and Mongo User Registration Adding Data to the Database

I NEED HELP!!!! server port works but gettin error in console as well.. Deprecation Warning

please help asap.. getting error when running nodemon.. server port is working but wont save anything from form into database. here is the error

$ nodemon [nodemon] 1.18.2 [nodemon] to restart at any time, enter rs [nodemon] watching: . [nodemon] starting node ./app (node:944) DeprecationWarning: current URL string parser is deprecated, and will be removed in a future version. To use the new parser, pass option { useNewUrlParser: true } to MongoClient.connect. Express app listening on port 3000 connection error: Error: Invalid schema, expected mongodb or mongodb+srv at module.exports (/Users/MarshB/UserAuthentication/node_modules/mongodb/lib/url_parser.js:21:21) at deprecated (internal/util.js:47:15) at connect (/Users/MarshB/UserAuthentication/node_modules/mongodb/lib/operations/mongo_client_ops.js:179:3) at connectOp (/Users/MarshB/UserAuthentication/node_modules/mongodb/lib/operations/mongo_client_ops.js:283:3) at executeOperation (/Users/MarshB/UserAuthentication/node_modules/mongodb/lib/utils.js:420:24) at MongoClient.connect (/Users/MarshB/UserAuthentication/node_modules/mongodb/lib/mongo_client.js:168:10) at Promise (/Users/MarshB/UserAuthentication/node_modules/mongoose/lib/connection.js:487:12) at new Promise (<anonymous>) at NativeConnection.Connection.openUri (/Users/MarshB/UserAuthentication/node_modules/mongoose/lib/connection.js:484:19) at Mongoose.connect (/Users/MarshB/UserAuthentication/node_modules/mongoose/lib/index.js:229:15) at Object.<anonymous> (/Users/MarshB/UserAuthentication/app.js:7:10) at Module._compile (module.js:652:30) at Object.Module._extensions..js (module.js:663:10) at Module.load (module.js:565:32) at tryModuleLoad (module.js:505:12) at Function.Module._load (module.js:497:3)

2 Answers

Ari Misha
Ari Misha
19,323 Points

Hello there! All I can say, from the error in your console, that There might be some syntax or Field error in your Schema. That's why it keeps saying Invalid Schema and won't let you add any entries in Mongo. Also, Deprecation Warning is something that you can ignore if you'd like to. But you're getting deprecation error coz you're using deprecated string parser lib/methods, you might wanna migrate to new URL string parser by mentioning { useNewUrlParser: true }.

~ Ari

Keegan Usher
Keegan Usher
26,226 Points

Hello,

Not sure if you got this error fixed yet. I added the "{useNewUrlParser: true}" option to the mongoose.connect line and the deprecation error stopped.

// mongodb connection
mongoose.connect('mongodb://localhost:27017/bookworm', {useNewUrlParser:true});
var db = mongoose.connection;
// mongo error
db.on('error', console.error.bind(console, 'connection error:'));

Hope this helps,

Keegan