mongodb cheat sheet for beginners
In this post, you will learn about MongoDB commands which could get you started and perform minimum database related activities such as create, update, drop a collection (table). These commands are ideally meant for MongoDB beginners and could be taken as the cheat sheet. You may want to bookmark this page for quick reference.
The following is the list of the commands:
sudo service mongod start sudo service mongod stop
mongo --host localhost:27017
show dbs
use testdb
Until a collection is created in a database, the database name is not listed as a result of execution of the command, “show dbs”
db.createCollection("user")
show collections show tables
The following command also work:
db.getCollectionNames()
db.user.insert({"name": "Ajitesh Shukla", "location": "hyderabad", "username": "eajitesh"})
db.user.find() db.user.find().pretty()
db.user.find({"username": "eajitesh"}) db.user.find({"username": "eajitesh", "location": "hyderabad"})
db.user.drop()
db.createUser({"user": "ajitesh", "pwd": "gurukul", "roles": ["readWrite", "dbAdmin"]})
show users
mongo -u USERNAME -p PASSWORD --authenticationDatabase DATABASENAME
For user created in above command, the login command would look like the following:
mongo -u ajitesh -p gurukul --authenticationDatabase testdb
In this post, you learned about the MongoDB cheatsheet commands (especially, helpful for beginners) which could help you quickly get started with MongoDB.
Did you find this article useful? Do you have any questions or suggestions about this article? Leave a comment and ask your questions and I shall do my best to address your queries.
Large language models (LLMs) have fundamentally transformed our digital landscape, powering everything from chatbots and…
As Large Language Models (LLMs) evolve into autonomous agents, understanding agentic workflow design patterns has…
In today's data-driven business landscape, organizations are constantly seeking ways to harness the power of…
In this blog, you would get to know the essential mathematical topics you need to…
This blog represents a list of questions you can ask when thinking like a product…
AI agents are autonomous systems combining three core components: a reasoning engine (powered by LLM),…