Nearby lessons
19 of 22🔤 MongoDB: Type Conversion and Checking Operators
MongoDB provides several type conversion and type checking operators
to transform field data types and verify data formats inside aggregation pipelines.
These operators are extremely useful when working with inconsistent or mixed-type data.
📚 Sample Collection Setup
1️⃣ Using $toString — Convert to String
2️⃣ Using $toInt — Convert to Integer
3️⃣ Using $toLong — Convert to 64-bit Integer
4️⃣ Using $toDouble — Convert to Floating-Point
5️⃣ Using $toDecimal — Convert to Decimal128
6️⃣ Using $toBool — Convert to Boolean
7️⃣ Using $toDate — Convert to Date
8️⃣ Using $toObjectId — Convert to ObjectId
9️⃣ Using $convert — Safe Type Conversion
🔟 Using $type — Check BSON Type
1️⃣1️⃣ Using $isNumber — Numeric Check
Keep Going!MongoDB - Conditional Operators