On this page
MongoDB Basics
Understanding BSON (Binary JSON)
- BSON (Binary JSON) is a binary representation of JSON-like documents.
- It extends JSON’s data model to provide additional data types, such as
Date
andBinary
. - BSON is used to encode data in MongoDB, making it efficient for storage and retrieval.
MongoDB Architecture
Databases
- Databases are containers for collections. Each MongoDB server can host multiple databases.
- The default database is
test
, but you can create new ones as needed.
Collections
- Collections are groups of MongoDB documents. They are analogous to tables in relational databases.
- Collections do not enforce a schema, meaning documents within a collection can have different structures.
Documents
- Documents are individual records in a collection, represented as BSON objects.
- Documents are similar to rows in relational databases but are more flexible due to their schema-less nature.
Basic Commands
-
Show Databases:
show dbs
-
Lists all databases on the server.
-
Use Database:
use <db>
- Switches to the specified database. If it doesn’t exist, MongoDB will create it when data is added.
-
Show Collections:
show collections
- Lists all collections in the currently selected database.