Introduction
BSON data types help MongoDB store and organize different kinds of information clearly and efficiently.
Jump into concepts and practice - no test required
BSON data types help MongoDB store and organize different kinds of information clearly and efficiently.
BSON data types include: - String - Integer - Double - Boolean - Date - Array - Object - ObjectId - Binary Data - Null - Regular Expression - Timestamp - Decimal128 - MinKey - MaxKey
{ name: "Alice", age: 30, active: true }{ scores: [85, 90, 78], joined: ISODate("2023-01-01T00:00:00Z") }{ _id: ObjectId("507f1f77bcf86cd799439011"), data: BinData(0, "...base64...") }This example inserts a user document with various BSON types and then retrieves it.
db.users.insertOne({
_id: ObjectId("507f1f77bcf86cd799439011"),
name: "Bob",
age: 25,
active: true,
scores: [88, 92, 79],
joined: ISODate("2024-01-15T10:00:00Z"),
profilePic: BinData(0, "VGhpcyBpcyBhIHRlc3Q=")
})
// Then find the document
db.users.find({ name: "Bob" })BSON types allow MongoDB to store data efficiently and support rich queries.
Using the right data type helps keep your data organized and easy to work with.
ObjectId is a special type used as a unique identifier for documents.
BSON data types define how MongoDB stores different kinds of data.
Common types include String, Integer, Boolean, Date, Array, and ObjectId.
Choosing the correct type helps MongoDB manage and query your data well.
{ "name": "Alice", "age": 30, "member": true }name, age, and member respectively?{ "date": "2023-01-01" }date field to be stored as a BSON Date type. What is the issue and how to fix it?