Chapter 4 Webx Ritesh
Chapter 4 Webx Ritesh
3. config Database
The config database is used in sharded clusters.
It stores all the metadata related to sharding and cluster configuration.
Contains collections like:
databases – list of databases in the cluster
collections – sharded collections
chunks – data chunk mapping to shards
Ex use config
db.databases.find();
Q4. Explain the concept of collection and document in MongoDB with
example?
Ans: MongoDB is a NoSQL database that stores data in a flexible, JSON-like
format called BSON (Binary JSON). The two core building blocks of
MongoDB data structure are:
Collections (equivalent to tables in relational databases)
Documents (equivalent to rows or records)
Document in MongoDB
A Document is the basic unit of data in MongoDB. It is a set of key-value
pairs, similar to a JSON object.
Documents are stored in BSON format.
They can contain nested documents (documents within documents).
Fields can store different data types: string, number, date, array, etc.
Ex {
"_id": 1,
"name": "Alice",
"age": 22,
"course": "Computer Science",
"subjects": ["DBMS", "OS", "MongoDB"]
}
Collection in MongoDB
A Collection is a group of documents. Think of it as similar to a table in SQL.
A collection does not require a fixed schema, so documents inside it can
have different fields.
Collections are created automatically when a document is inserted.
We can create a collection by using db.createCollection("students").
Q6. What does REST stand for? Explain REST API with basic flow diagram?
Ans: REST stands for Representational State Transfer.
A REST API (or RESTful API) is an interface that allows communication
between client and server using standard HTTP methods.
It allows CRUD (Create, Read, Update, Delete) operations on resources using:
GET, POST, PUT, DELETE methods.