5 Differences between SQL and NoSQL databases
| SQL | NoSQL |
|---|---|
| Relational Database | Non-Relational/Distributed Database |
| Table Based | Document Based, Key-Value Pairs, Graph DB, or Wide-Column Stores |
| Predefined Scheme | Dynamic Schema for unstructured data |
| Vertically scalable (Increase HP of Hardware) | Horizontally Scalable (Increase # of Servers) |
| SQL defines and manipulates data | Queries focus on collections of documents |
SELECT id, name, price FROM products
SELECT & FROM are keywordsid, name, price, and products are parameters
id - price are column headers in the databaseproducts is the database we want to queryFields (Columns) and Records (Rows)Users table stores all customer infoProducts table stores all product informationOrders table is created from Users and Products by combining information about products and users to create an order sheetCollections and DocumentsDocuments
Documentstry and Promise
try says, “try this block of code”Promise says, “I’m expecting data”
Promise.resolve(<variableName>) will accept the data if the code worksPromise.reject(<variableName>) will throw an error if the data doesn’t meet the required conditions.resolve and .reject so that there is not a hanging promise in your code, which will cause issues with your codeschema in order to do the labODM (Object Document Mapping)
Mongoose as an ODM
Mongoose
npm i mongooseMongoose to the server.js file with const mongoose = require('mongoose')Defining the schema within the appropriate component on the backend
const { Schema } = mongoose;
const dataSchema = new Schema {
key1: value1,
key2: value2,
key3: value3
};
Add this code block to the server.js file for a proof of life that Mongoose is connected and working properly:
// add validation to confirm we are wired up to our mongo DB
const db = mongoose.connection;
db.on('error', console.error.bind(console, 'connection error:'));
db.once('open', function () {
console.log('Mongoose is connected');
});
0.0.0.0/0Database => Connect => Connect your applicationDB_URL to .env file
/ and before the ? to add the name of the database and replace <password> with the password taken from below:
Database Access and setup a password => Update User Info