Friday, October 21st, 2022
MongoDB is a NoSQL, document-based database management system. It was created in 2007 by MongoDB Inc. (formerly known as 10gen).
Contrasting MongoDb and SQL
SQL (Structured Query Language) and MongoDB are two different types of databases, each with its own strengths and weaknesses. Here are some key differences between the two:
Data Model:
Schema:
Query Language:
Scaling:
While SQL is a mature and well-established technology, widely used for its ability to enforce data consistency and relationships, MongoDB is a newer technology, designed for fast and flexible storage of semi-structured data, and scalability. The choice between the two will depend on the specific requirements of the application and the nature of the data being stored.
MongoDB Structure, Databases and Collections
In MongoDB, a database is a top-level container for collections, which are similar to tables in SQL databases. Each collection can store multiple documents, and each document can have different fields. Indexes are used in MongoDB to improve query performance and can be created on specific fields within a document.
MongoDB, Sample Queries
db.collection.find({})
db.collection.find({field: value})
db.collection.find({}).limit(n)
db.collection.find({}).sort({field: 1})
db.collection.updateOne({field: value}, {$set: {field: newValue}})
db.collection.updateMany({field: value}, {$set: {field: newValue}})
db.collection.deleteOne({field: value})
db.collection.deleteMany({field: value})
db.collection.aggregate([
{$match: {field: value}},
{$group: {_id: "$field", total: {$sum: "$value"}}}
])
MongoDB, Common Tools
Overall, MongoDB is a popular choice for modern web and mobile applications due to its flexible data model, scalability, and performance.