MongoDB Basics and mongo Shell Commands
MongoDB Basics and mongo Shell Commands
- NO SQL database.
- Data is stored as BSON format (i.e. same as our good old JSON but more optimized, see picture!)
- Comparison with RDBMS:
- Database = "Database"
- Tables = "Collections"
- Rows = "Document"
mongo vs mongod
-> mongo
A Programmer writes Commands in this Shell.Automatically starts at 27017 port of our local host
The Command line Shell that connects to specific instance of "mongod" (mongoDataBase).
-> mongod
The Host Process of our Database. FUN FACT :- mongo was also called mongosh before.
Handy mongo shell commands.
db => | shows the current working db |
use name_of_the_database => | creates(if it doesn't exist) or switches(if it already exists) to the named database |
show dbs => | shows all databases |
db.dropDatabase() | deletes the current working db |
show collections => | shows all collections |
FACT - A database doesn't count to be made if it doesn't have any collection(document).
db.collection_name.insert({"name":"rishabh", "branch":'IT"});
db.collection_name.insertOne({"name":"rishabh", "branch":'IT"});
db.collection_name.insertMany([{"name":"rishabh", "branch":'IT"},{"name":"gourav" , "branch":"IT"}]);
CLOSING NOTE - That's pretty much all the commands we will ever use as a software developer directly on mongo Shell.
Next up : Please see Authentication in MongoDB Blog for database Permissions and Users.
Comments
Post a Comment