MongoDB Shell (mongosh) Introduction

 Introduction to MongoDB Shell (mongosh)


The MongoDB Shell, known as mongosh, is an interactive JavaScript interface to MongoDB. It allows you to connect to your MongoDB databases, run queries, inspect documents, and manage collections and databases using a command-line interface (CLI).


What is mongosh?


mongosh is the modern replacement for the older mongo shell and is the default shell for MongoDB starting from version 5.0+.

Key Features:


Feature


JavaScript-based


Intuitive


Autocompletion


Supports MongoDB


CRUD Operations


Connection to Local


or Remote Databases


Built-in Help


Description


You can run J and use varia functions, loo


Helps with co collection nar operators.


Create, Read, Delete operat


Connect to cl or self-hosted instances.


Use .help to command opi



How to Start mongosh


1. Install mongosh (if not installed)


*On Ubuntu/Debian:

*On macOS (with homebrew):



*On Windows: Download from MongoDB Downloads

*Connect to MongoDB



*This connects to the default MongoDB


instance (mongodb://localhost:27017).


Or specify a URI":



*basic mangosh commands

Command


Description


show dbs


use <db>


Lists all datal


Switches to a database


show collections


Lists collectic


db.<collection>.find ()


db.createCollection( "name")


current datab


Finds docume collection


Creates a nev collection


db.<collection>.inse


Inserts a sing


document


rtOne({...})


db.<collection>.upda Updates a sin teOne({...}, {...})


db.<collection>.dele teOne({...})


document


Deletes a sin document


exit


Exits the shel

*Example session 




Pranav narade

University: Shree Balaji University, Pune

School: School of Computer Studies

Course: BCA (Bachelor of Computer Applications)

Interests: NoSQL, MongoDB, and related technologies

📸 Instagram 🔗 LinkedIn 🌐 Official Website   

Comments

Post a Comment

Popular posts from this blog

MongoDB Master Guide

Covered Queries and Index Queries in MongoDB