MoongoDB database, Document based structure, Schema flexibility, MongoDB database and Insert Documents in database
MoongoDB database
Companies used MoongoDB :
Netflix : content management and
user preference
Uber : Real time location and Driver
Management
Meta : Social Media and user info storage
Intro:
MOONGODB is a NoSQL database. That
means “no only SQL”.
It is document oriented storage.
It has two main concepts
a. document based structure
b. schema flexibility.
Document based structure
It stores data in the form of
documents, which are BSON (Binary JSON) objects.
These documents are like records
but more flexible.
For each document its structure
varies.
Sponser content:
Schema flexibility:
No Predefined schema.
MongoDB collection are
Schema-less, which means there is no strict schema that enforces which fields must
exists on their data types.
Each documents have its own
unique set of fields, or they can share fields but with different datatypes.
Eg:
{
title: "Post Title 1",
body: "Body of post.",
category: "News",
likes: 1,
tags: ["news", "events"],
date: Date()
}
Sponser content:
MongoDB database:
What is MongoDB Atlas?
MongoDB Atlas is a multi-cloud database service by the same people that build MongoDB. Atlas simplifies deploying and managing your databases while offering the versatility you need to build resilient and performant global applications on the cloud providers of your choice.
MongoDB Query API
it is the way you will interact with your data.
The MongoDB Query API can be used in two ways:
- CRUD Operations
- Aggregation Pipeline.
MongoDB Query API Uses
You can use the MongoDB Query API to perform:
- Adhoc queries with mongosh, Compass, VS Code, or a MongoDB driver for the programming language you use.
- Data transformations using aggregation pipelines.
- Document join support to combine data from different collections.
- Graph and geospatial queries.
- Full-text search.
- Indexing to improve MongoDB query performance.
- Time series analysis.
Create Database using mongosh
After connecting to your database using mongosh
, you can see which database you are using by typing db
in your terminal.
If you have used the connection string provided from the MongoDB Atlas dashboard, you should be connected to the myFirstDatabase
database.
Sponser content:
"This Content Sponsored by Genreviews.Online
Genreviews.online is One of the Review Portal Site
Website Link: https://genreviews.online/
Sponsor Content: #genreviews.online, #genreviews, #productreviews, #bestreviews, #reviewportal"
Show all databases
To see all available databases, in your terminal type "show db".
Notice that myFirstDatabase
is not listed. This is because the database is empty. An empty database is essentially non-existant.
Change or Create a Database
You can change or create a new database by typing use
then the name of the database.
Insert Documents
There are 2 methods to insert documents into a MongoDB database.
insertOne()
To insert a single document, use the insertOne()
method.
Sponser content:
This method inserts a single object into the database.db.posts.insertOne({
title: "Post Title 1",
body: "Body of post.",
category: "News",
likes: 1,
tags: ["news", "events"],
date: Date()
}
Comments
Post a Comment