App is not connecting to the mongodb Atlas - javascript

I start learning JavaScript on the freecodecamp and stuck on a challenge.
The challenge itself is to setup a mongoose.
But every time I am submitting my answer it giving me an error of "mongoose should be connected to a database.
I checked the fcc forum on the same topic and all of the solutions not working for me
The challenge provide the starting code and all what is required is to setup mongo atlas and connect your app to it
In the app.js you should add
require("dotenv").config();
let mongoose = require("mongoose");
mongoose.connect(process.env.MONGO_URI, {
useUnifiedTopology: true,
useNewUrlParser: true
});
in the .env file
MONGO_URI=mongodb+srv://userName:password#cluster0.rmycu.mongodb.net/myFirstDatabase
Where the userName and password are changed to mine without any prohibited symbols.
You should also add this dependencies to package.json
"mongodb": "4.1.1",
"mongoose": "6.0.5"
Any help appreciated

Can you try to change connection config and use it without additional options:
mongoose.connect(process.env.MONGO_URI);
Since you are using Mongoose version higher than 6.0, these options are not available as config anymore, and are configured automatically.

Related

MongooseServerSelectionError: connect ETIMEDOUT 13.250.154.115:27017

While I'm working on my school project, This error just randomly showed up.
Error connecting to MongoDB: MongooseServerSelectionError: connect ETIMEDOUT 13.250.154.115:27017
even in the compass is not working, I tried to run my other project that has a MongoDB connection and they are all inputting the same error
I tried to search it before asking this. this is what I already did
-terminating cluster and creating new
-check the IP address in network access and it's in public
-restart my laptop
-creating a new MongoDB account
-doubled check the URI
enter image description here
enter image description here
is there having the same problem as me that is being solved?
btw I'm using mern stack
try this :
mongoose.connect(process.env.MONGO_URI,{ useNewUrlParser: true, useUnifiedTopology: true });
In order to better understand these options, I strongly recommend you to read the Mongoose documentation about the deprecation warnings.
https://mongoosejs.com/docs/5.x/docs/deprecations.html

How can I set database authentication in Mongodb - Is SSH Pipes better for MongoDB?

I have installed MongoDB in my computer. I did't define any password and username for the installation. I can see everything with Robo 3T.
Now I want to protect my database.
I have tried to set authentication for the database. I followed https://docs.mongodb.com/manual/tutorial/enable-authentication/ . It did not work.
I still can reach mongodb with robo 3t and see all information.
I have also tried to start mongodb with --auth parameter. I have define a configuration file looks like
And for starting mongodb
mongod -f C:\mongodb\conf\mongodb.conf
Mongodb has been started but, it did not ask any pass. And I can save simple data with Postman without authentication.
What I want to do:
Protect my database against Robo 3t. :))
I dont want to save any data without auth.
Building Nodejs connection string that include pass like
mysql://root:password#localhost:port/dbName
Here is my Nodejs index.js code
this is my model.
PS: I am very new in Nodejs and Mongodb.
EDIT: inside conf file

Sequelize Deprecated Error Message when running migration

Hello guys Im beginner in Sequelize and Node js,
I have read their offical docs, read their github, searched blog post and couldnt solve it.
Im constantly getting warning messages :
GMT sequelize deprecated String based operators are now deprecated. Please use Symbol based operators for better security, read more at http://docs.sequelizejs.com/manual/tutorial/querying.html#operators at node_modules/sequelize/lib/sequelize.js:236:13
This error is only happening when running migrations but this is not happening when Im starting server normally
Herei is my connection.js file
https://pastebin.com/5NKfExib
So I googled for few days and here is the answer:
operator alliases must be set to false when connecting to database like this:
sequelize = new Sequelize(config.database, config.username, config.password, Object.assign({}, config, {
pool: dbConst.pool,
operatorsAliases: false,
})
Also in migrations.config.json, operatorAliases must be set to false
And in your code always use Sequalize.Op

Point mongoos.connect at localhost mongodb

I am studying the MEAN stack by using this tutorial. But the tutorial connects to a remote mongodb installation. I have MongoDB running in the CentOS7 localhost.
How do I alter the mongoose connect line in server.js from the tutorial link above to connect to a localhost database instead of a remote database?
Here is the current line from server.js that needs to be changed to point to the localhost mongodb:
mongoose.connect('mongodb://node:nodeuser#mongo.onmodulus.net:27017/uwO3mypu');
A specific mongodb database has not been created yet. Do I need to create that also?
I'm fairly new at Mongo to, but I know how to connect to a local db. Basically I had to do the following:
Download the latest version of mongodb from https://www.mongodb.com/download-center?jmp=nav#community (according to your settings)
Once installed, I've created a folder that will be containing my DB.
Use a command line instance to start mongo like this:
mongod --dbpath [YOUR_DB_PATH]
Created a DB use mydb
With that you should have already a mongodb db instance looking for connections on default port. So you can change that line for this:
mongoose.connect('mongodb://localhost:27017/mydb');
Again, this is really basic and it is creating a mongo DB connection with all default options. So this will keep you rolling, but you may need to dig a bit more for custom options.
Hope this helps

I need to create a simple database for use in an Angular/Node demo. What is the path of least resistance to adding such a database to my demo?

I need to create a simple database for use in an Angular/Node demo. What is the path of least resistance to adding such a database to my demo?
Incidentally, I cannot use the MEAN stack.
Edit: I failed to mention that I'm running the demo from my local environment--from my laptop.
The path of least resistance would be to use Sequelize and sqlite3 in your application.
Start off by running npm install sequelize sqlite3.
Then in your code
var Sequelize = require( 'sequelize' )
var connection = Sequelize.connect( undefined, {
dialect: 'sqlite',
storage: __dirname + '/db.sqlite'
})
Tada, you have a database connection syncing to a local sqlite DB.
You'll likely need to consult the Sequelize documentation to use this connection.
If, however, you wanted an API for your angular demo, json-server is what you're looking for.

Categories

Resources