Install and Set Up Mongoose help - write concern

I have been trying to pass this test for hours now. I have tried every solution possible and it still isn’t working. Keep on getting “mongoose is not connected.” Please help!

Here’s my code:
myApp.js

var mongodb = require('mongodb');
const mongoose = require('mongoose');
mongoose.connect(process.env.MONGO_URI);

.env:

MONGO_URI=mongodb+srv://username:password@cluster0-qhh1b.mongodb.net/test?retryWrites=true&w=majority

package.json:

{
  "name": "fcc-mongo-mongoose-challenges",
  "version": "0.0.1",
  "description": "A boilerplate project",
  "main": "server.js",
  "scripts": {
    "start": "node server.js"
  },
  "dependencies": {
    "express": "^4.16.4",
    "body-parser": "^1.19.0",
    "mongoose": "^5.5.12",
    "mongodb": "^3.2.6"
  },
  "engines": {
    "node": "^4.4.5"
  },
  "repository": {
    "type": "git",
    "url": "https://hyperdev.com/#!/project/welcome-project"
  },
  "keywords": [
    "node",
    "hyperdev",
    "express"
  ],
  "license": "MIT"
}

I have whitelisted my IP address so that it is allowed from everywhere.
Nothing is working.

remove that part from the end your connection string and try it, I’m looking into why that is being added to the end of the connection string, this is the second time I have now seen this.

https://docs.mongodb.com/manual/reference/write-concern/#writeconcern.dq_majority_dq

I’m not sure if it is glitch that is causing this issue with the write concern or a driver issue or something else, but atlas just recently added it to the end of the string, it was not this way a couple weeks ago, If somebody could try connecting to the string locally we can verify that at least it is not glitch, if it is glitch then maybe the template can be changed

edit: @isheetac I have edited your title to merge other future threads into this with the same issue so we can target it better, thanks.

@RandellDawson, just ‘atting’ you since you are most familiar with this issue here, there maybe a modification that mongodb atlas made in the connection string in the last few weeks that prevents users from connecting with glitch, it is resolved by removing the &w=majority from the end of the connection string, but I’m not sure yet of the cause or what could be a perma-fix.

Thank you for the response. I have removed the ‘&w=majority’ from the connection string to see if that changes anything but it still isn’t working.

I can’t say without looking at your glitch link, and even then it is likely that it is an issue with the way you got your connection string rather than glitch itself, I have confirmed however that you must remove &w=majority for it to work , haven’t had the time to figure out the why’s and hows for the moment.

Any other thoughts to this? I am at this challenge and can ONLY pass the challenge if I do not use process.env.MONGO_URI

Rather, I have to input the entire URI string in myApp.js for it to pass the Challenge:

mongoose.connect('mongodb+srv://sidneyyin:password98765@cluster0-4luoc.mongodb.net/test?retryWrites=true');

Because it passes if I put in the URI directly inside quotes, I have deduced that the problem wasn’t:

  • White listing

  • Password error

  • Dependency error in the package.json file

Could it be that I am entering the .env file wrong?

This is what I have in the .env file:


SECRET=
MADE_WITH=
MONGO_URI=mongodb+srv://sidneyyin:password98765@cluster0-4luoc.mongodb.net/test?retryWrites=true