"dependencies": {
"express": "^4.12.4",
"body-parser": "^1.15.2",
"mongodb" : "^3.6.8",
"mongoose" : "^5.3.9"
},
const mongoose = require('mongoose');
mongoose.connect(process.env.MONGO_URI);
MONGO_URI=mongodb://simba:$123simba@ds131963.mlab.com:31963/databazz
The error says mongoose isn’t connected…plzz help!!
Hi, I think you don’t need to add mongo dependency. But you need to import .env, and add the uri in .env file.
Check on your mlab account the exact url of the db, it includes mongodb:// at begining.
Best regards
You called MONGO_URI
before you set the actual variable.
Put the line below before the one about mongoose.connect()
const MONGO_URI="mongodb://simba:$123simba@ds131963.mlab.com:31963/databazz"
Follow this Getting Started instructions from the mongoose docs for more details.
I’ve included mongodb:// in the beginning,…it’s still not working…
You’re reading the MONGO_URI
from process.env
, did you setup that correctly? If not you can always use directly like:
const mongoose = require('mongoose');
mongoose.connect('simba:$123simba@ds131963.mlab.com:31963/databazz');
Can anyone help…I’ve now deleted the previous user and changed the password in a way that it not includes special characters…still it’s showing error.
I got the perfect solution
mongoose.connect(process.env.MONGO_URI, { useNewUrlParser: true });
use this and at private environment file use your database name and database password and the test will pass
ap3
February 6, 2019, 3:48am
10
Which file did you add this on?
ap3
February 6, 2019, 3:54am
11
Figured it out, in the myApp.js. The { useNewUrlParser: true }
isn’t necessary.
Has anybody been able to do this with the new uri? You can’t get an mlab uri anymore…
This is the new URI:
mongodb+srv://mscanza:password@fcc-vcnna.mongodb.net/test?retryWrites=true
I’ve been unable to connect to Mongoose. Any help would be greatly appreciated. It passes the dependencies tests. The error keeps saying:
(node:6705) UnhandledPromiseRejectionWarning: MongoNetworkError: connection 4 to fcc-shard-00-00-vcnna.mongodb.net:27017 closed
Were you able to figure this out? I’m having a similar issue
Yes, this may help:
---
title: Introduction to the MongoDB and Mongoose Challenges
block: MongoDB and Mongoose
superBlock: APIs and Microservices
---
## Introduction to the MongoDB and Mongoose Challenges
MongoDB is a database that stores data records (documents) for use by an application. Mongo is a non-relational, "NoSQL" database. This means Mongo stores all data associated within one record, instead of storing it across many preset tables as in a SQL database. Some benefits of this storage model are:
- Scalability: by default, non-relational databases are split (or "shared") across many systems instead of only one. This makes it easier to improve performance at a lower cost.
- Flexibility: new datasets and properties can be added to a document without the need to make a new table for that data.
- Replication: copies of the database run in parallel so if one goes down, one of the copies becomes the new primary data source.
While there are many non-relational databases, Mongo's use of JSON as its document storage structure makes it a logical choice when learning backend JavaScript. Accessing documents and their properties is like accessing objects in JavaScript.
Mongoose.js is an npm module for Node.js that allows you to write objects for Mongo as you would in JavaScript. This can make it easier to construct documents for storage in Mongo.
Working on these challenges will involve you writing your code on Glitch on our starter project. After completing each challenge you can copy your public glitch url (to the homepage of your app) into the challenge screen to test it! Optionally you may choose to write your project on another platform but it must be publicly visible for our testing.
Start this project on Glitch using [this link](https://glitch.com/#!/import/github/freeCodeCamp/boilerplate-mongomongoose/) or clone [this repository](https://github.com/freeCodeCamp/boilerplate-mongomongoose/) on GitHub! If you use Glitch, remember to save the link to your project somewhere safe!
This file has been truncated. show original