MongoDB — Data Types
BSON Data Types
| Type | Description | Example |
|---|---|---|
| String | Text | "Hello" |
| Integer | Whole number | 42 |
| Double | Floating point | 3.14 |
| Boolean | True/false | true |
| Array | List | [1, 2, 3] |
| Object | Embedded document | { key: "value" } |
| ObjectId | Unique identifier | ObjectId("...") |
| Date | Date/time | new Date() |
| Null | Null value | null |
String
{ name: "John Doe" }
Number
{ age: 30, price: 19.99 }
Boolean
{ active: true }
Array
{ hobbies: ["reading", "gaming"] }
Object
{
address: {
street: "123 Main St",
city: "New York"
}
}
Date
{ createdAt: new Date() }
ObjectId
{ _id: ObjectId("507f1f77bcf86cd799439011") }
Mini Practice
- Use different data types
- Create nested objects
- Use arrays
- Work with dates
Up Next
Continue with Insert — inserting documents.
Related Topics
Frequently Asked Questions about Data Types
What is Data Types in MongoDB?
Data Types is a fundamental concept in MongoDB. This lesson explains it step by step with clear examples, making it easy for beginners to understand.
How do I learn Data Types?
Start by reading the explanation above, then try the code examples. Practice by modifying the examples and experimenting with different values. Hands-on practice is the best way to learn Data Types.
Why is Data Types important in MongoDB?
Data Types is essential for MongoDB development. Understanding this concept will help you write better code and solve real-world problems more effectively.