(STRANGE ERROR!) MongoDB and Mongoose - Install and Set Up Mongoose

Hi all,

Glitch Project Link
https://glitch.com/~sophisticated-anaconda

Glitch LiveApp Link
https://sophisticated-anaconda.glitch.me

I’ve been struggling with this topic for a day already, checked all the previous posts, but found nothing related to my problem.

Error message in Glitch Log window:
at Object. (/app/server.js:61:14)

Clicked on the message, which jumps to the below line in server.js
var Person = require(’./myApp.js’).PersonModel;

I have no idea why this line is causing an error, I did not modify any part of server.js

Following is what I have for each section in Glitch file

.env
MONGO_URI=mongodb+srv://dulerong:MYPASSWORD@cluster0-dgpw6.mongodb.net/test?retryWrites=true&w=majority

MYPASSWORD: I’ve replaced it with my own password, consisting of only alphabets and numbers. Also, removing the <> characters.

myApp.js

const mongoose = require(‘mongoose’);
mongoose.connect(process.env.MONGO_URI, { useNewUrlParser: true, useUnifiedTopology: true });

package.json
“dependencies”: {
“express”: “^4.12.4”,
“body-parser”: “^1.15.2”,
“mongodb”: “^3.0.0”,
“mongoose”: “^5.6.5”
},

I’ve only added the two monogo lines for dependencies.
This is it, I’ve made no other changes to the original Glitch file, readily available in the Mongo section introduction, for beginners like me.

What’s interesting is:
If I delete the lines in myApp.js (shown below), I’d actually pass 2 of the 3 checks in the problem

  1. “mongodb” dependency should be in package.json (pass)
  2. “mongoose” dependency should be in package.json (pass)
  3. “mongoose” should be connected to a database (fail)

myApp.js (if i delete this, I’d actually get 2 out of 3 checked passed)

const mongoose = require(‘mongoose’);
mongoose.connect(process.env.MONGO_URI, { useNewUrlParser: true, useUnifiedTopology: true });

Guys, I really have no idea why this is happening, I did exactly what I was told to do with correct syntax, please help me. Thank you.

Codey

Can you post the actual Glitch project link, so we can take a look around at the full code?

Dear Sir,

I’ve posted both Glitch Project and LiveApp link in my original post, at the top.

Thanks for your time.

Codey

It might be simple, but try the URI in quotes:

.env
MONGO_URI="mongodb+srv://dulerong:MYPASSWORD@cluster0-dgpw6.mongodb.net/test?retryWrites=true&w=majority"
2 Likes

@pjonp

Thank you so much, yes this did help, putting quotes around my URI.

I feel so glad now that I’ve wrestled with this problem over a day!

Cheers!
Codey