Connect to the Database
We are Connecting to the database.
mongosh "mongodb+srv://cluster0.ex4ht.mongodb.net/myFirstDatabase" --apiVersion 1 --username YOUR_USER_NAME
Create a Collection During The Insert Process
We are creating a collection during the insert process.
db.posts.insertOne(object)
Create a new Database called blog
We Creating a new database called blog.
use blog
Create Collection
we Creating Collection.
db.createCollection("posts")
Insert Documents
We are inserting documents.
db.posts.insertOne({ title: "Post Title 1", body: "Body of post.", category: "News", likes: 1, tags: ["news", "events"], date: Date() })
To verify that MongoDB has been installed properly
To verify that it has been installed properly, open your terminal and type.
mongosh --version