DEV Community

Code_Regina
Code_Regina

Posted on

|Database| Database: MongoDB

          -Introduction to Database
          -SQL vs. NoSQL Database
          -Why Mongo
          -Inserting with Mongo
          -Updating with Mongo
Enter fullscreen mode Exit fullscreen mode

Introduction to Database

Why use a database instead of just saving to a file?

Databases can handle large amounts of data efficiently and store it compactly. They provide tools for easy insertion, querying and updating of data. Databases generally offer security features and control over access to data.

SQL vs. NoSQL Database

SQL Databases also known as structured query language databases. Relational databases are pre-defined schema of tables before any information that is inserted into them.

NoSQL databases do not use SQL. There are many types of no-sql databases, including document, key-value, and graph stores.

Popular SQL Databases
MySQL, Postgres, SQLite,Oracle, Microsoft SQL Server

Popular No-SQL Databases
MongoDB, CouchDB, Neo4j, Cassandra, Redis

Why Mongo

Mongo is very commonly used with Node and Express (MEAN and MERN stacks).
It's easy to get started with, popularity also means there is a strong community of developers using Mongo.

Inserting with Mongo

When a collection does not currently exist, insert operations will create the collection.


db.collection.insertOne()

Enter fullscreen mode Exit fullscreen mode

will insert a single document into a collection.

it is possible to insert a single document and to insert many documents.

insertMany()

Enter fullscreen mode Exit fullscreen mode

The insert() method can insert either single or many documents.

insert()
Enter fullscreen mode Exit fullscreen mode

Top comments (0)