Closed mysticBel closed 2 years ago
Network Access
to any IP using 0.0.0.0/0
as whitelist entry.
This will allow to use our mongo atlas cluster from any IP address.
Once done, click Confirm.Database Access
--> Create Database User with Name and Password
👀REMEMber : We will need this info to put into our project later Clusters
, click on Connect your application
,
👀 copy the Connection String.// import mongoose 💚
const mongoose = require('mongoose');
//db connection
mongoose.connect(
' _paste here the URI, it is a string so use single quotes for it, also put your password!!!_ ',
{useNewUrlParser: true}
)
.then(() => console.log('DB Connected :D yay! '))
mongoose.connection.on('error', err => {
console.log(`DB connection error: ${err.message}`)
});
That's all. Now you can use this connection string to use mongodb in the cloud (mongoDB Atlas) 🦄✨
https://www.freecodecamp.org/news/introduction-to-mongoose-for-mongodb-d2a7aa593c57/
MongoDB is a schema-less NoSQL document database. It means you can store JSON documents in it, and thestructure of these documents can vary
as it is not enforced like SQL databases. This is one of the advantages of using NoSQL as it speeds up application development and reduces the complexity of deployments.
Below is an example of how data is stored in Mongo vs. SQL Database:
Terminologies
‘Collections’ in Mongo are equivalent to tables in relational databases. They can hold multiple JSON documents.
‘Documents’ are equivalent to records or rows of data in SQL. While a SQL row can reference data in other tables, Mongo documents usually combine that in a document.
‘Fields’ or attributes are similar to columns in a SQL table.
While Mongo is schema-less, SQL defines a schema via the table definition. A Mongoose ‘schema’ is a document data structure (or shape of the document) that is enforced via the application layer.
‘Models’ are higher-order constructors that take a schema and create an instance of a document equivalent to records in a relational database.
Mongoose is an Object Data Modeling (ODM) library for MongoDB and Node.js.
It's an object modeling tool designed to work in an asynchronous environment.
Mongoose supports both promises and callbacks.
It manages relationships between data
, provides schema validation
, and is used
to translate between objects in code
and the representation of those objects in MongoDB.
// Using Node.js `require()`
const mongoose = require('mongoose');
// Using ES6 imports
import mongoose from 'mongoose';