Skip to content

Latest commit

 

History

History
41 lines (28 loc) · 1.68 KB

02_CreateDB.md

File metadata and controls

41 lines (28 loc) · 1.68 KB

Creating a database, collection and adding data to it using MongoDB-Compass

image

  • 1st + → creating a connection
  • 2nd + → creating database
  • 3rd → creating a collection

Add data > insert document

image

Data added

image

There is no need for schema here. "schema" refers to the structure of the data, including the fields and their data types. Unlike traditional relational databases like MySQL , which enforce a strict schema at the database level, MongoDB is schema-less or schema-flexible. This means:

  • No Fixed Schema: Collections do not enforce a fixed schema. Documents within the same collection can have different sets of fields, and the data types for the same field can vary across documents.
  • Dynamic Schema: You can add or remove fields from documents without having to update a central schema definition. This allows for more flexibility and faster iteration during development.
  • Nested Data Structures: MongoDB supports nested documents and arrays, allowing for more complex data representations within a single document.
_id: ObjectId('66d6c04165421871b216b8cf')
name : "Swati"
role : "Devops"

_id: ObjectId('66d6c10365421871b216b8d0')
name : "Niall"
location: "San Fransisco"

Basic Commands

show dbs

image

use <database-name>

image