Welcome to our comprehensive MongoDB cheatsheet designed to empower MongoDB beginners with essential commands. Whether you're navigating databases, collections, or rows (documents), this guide covers the commands you need to kickstart your MongoDB journey.
let's familiarize ourselves with some key MongoDB concepts:
Now, armed with a basic understanding of these terms, let's explore the essential commands you'll need to kickstart your MongoDB journey.
show dbs
use dbName
db
db.dropDatabase()
show collections
db.createCollection('collector')
db.collector.drop()
db.collector.find()
db.collector.find().pretty()
db.collector.findOne({name: 'Naman'})
db.collector.insert({
'name': 'Naman',
'lang': 'TypeScript',
'member_since': 5
})
db.collector.insertMany([{
'name': 'Naman',
'lang': 'TypeScript',
'member_since': 5
},
{'name': 'Rohan',
'lang': 'Python',
'member_since': 3
},
{'name': 'Lovish',
'lang': 'Java',
'member_since': 4
}])
db.collector.find({lang:'Python'})
db.collector.find().limit(2)
db.collector.find().count()
db.collector.updateOne({name: 'Shubham'},
{$set: {'name': 'Naman',
'lang': 'TypeScript',
'member_since': 51
}}, {upsert: true})
db.collector.update({name: 'Rohan'},
{$inc:{
member_since: 2
}})
db.collector.update({name: 'Rohan'},
{$rename:{
member_since: 'member'
}})
db.collector.remove({name: 'Naman'})
db.collector.find({member_since: {$lt: 90}})
db.collector.find({member_since: {$lte: 90}})
db.collector.find({member_since: {$gt: 90}})
db.collector.find({member_since: {$gte: 90}})
And there you have it—a comprehensive MongoDB cheatsheet for beginners. Armed with these commands, you're ready to navigate databases, collections, and documents with confidence. Dive into your MongoDB journey, practice these commands.
Happy Coding!
Technical Author with a passion for translating the complexities of software, computers, and emerging technologies into accessible and engaging content. Armed with a background in computer science, I blend technical expertise with a flair for effective communication in my writing. Join me on this tech-savvy journey as we explore coding languages, unravel the nuances of software architecture, and stay informed about the latest tech trends. Let's navigate the digital frontier together!