Double (Double-Precision Float)
Last updated: 2026-10-09
Double (Double-Precision Float)
Double is MongoDB's default numeric type: a 64-bit IEEE 754 float, roughly ±1.8×10^308. Bare numbers in mongosh (like 3.14) are Doubles by default. Use it for measurements, percentages, and coordinates; choose Decimal128 for money that must be exact.
| Category | BSON Types |
|---|---|
| MongoDB Version | 1.0+ |
| Example Language | mongosh (Shell) |
📝 Syntax
{ price: 3.14 } // bare literal is Double
NumberDouble(3.14) // explicit
{ price: { $lt: 10.5 } }
Returns:Returns a Double BSON float
▶ Example
Run the commands below in your local mongosh (requires a running mongod):
// Double: comparison and aggregation
use shop
db.products.find({ price: { $gte: 9.99 } })
db.products.aggregate([{ $group: { _id: null, avg: { $avg: '$price' } } }])
Output:
// Products with price >= 9.99, plus the average price
📌 Notes
- 0.1+0.2 != 0.3 in Double; use Decimal128 for money
- Bare integer 42 is also a Double in mongosh
- $eq won't match a Double against Int32; convert with $convert
🏷️ Related Tags
💡 Related Cases
📚 Related Tutorials
❓ FAQ
QDouble or Decimal128?
ADouble for approximate math (measurements, coordinates); Decimal128 for exact decimal money.
QWhat type is 42 in mongosh?
ADouble. Use Int32(42) or Long(42) when you need an integer.
QHow many significant digits does a Double have?
AAbout 15-17 significant decimal digits; beyond that it rounds in binary.