BSON फॉर्मेट
MongoDB documents BSON में store करता है, JSON का एक binary form जो dates, integers, और ObjectId जैसे extra types add करता है।
In this page:
Syntax
{
field: "text",
count: NumberInt(value),
created: new Date(),
_id: ObjectId()
}
BSON Format
BSON (Binary JSON) on-disk और wire format है। यह JSON की structure रखता है लेकिन Date, ObjectId, Int32, Int64, Decimal128, Binary, और Timestamp जैसे types add करता है, और यह fast to scan design हुआ है।
आप इसे tools और drivers में extended JSON की तरह देखते हैं।
Note:
floating-point rounding surprises से बचने के लिए money के लिए Decimal128 इस्तेमाल करें।
उदाहरण: BSON format
test> db.types.insertOne({
... _id: 1,
... name: "sample",
... count: Int32(5),
... big: Long("9007199254740993"),
... price: Decimal128("19.99"),
... created: ISODate("2024-01-05T10:00:00Z")
... })
{ acknowledged: true, insertedId: 1 }
test> db.types.findOne()
{
_id: 1,
name: 'sample',
count: 5,
big: Long('9007199254740993'),
price: Decimal128('19.99'),
created: ISODate('2024-01-05T10:00:00.000Z')
}
⚠️ Run this in your own terminal or Node.js environment.
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the
view already swaps in the hi_ translation fields (or blanks these
out if untranslated), so this renders correctly for both languages
without a lang_code check here. #}
आम गलतियां
- यह मान लेना कि JSON dates strings की तरह store होती हैं
- currency के लिए doubles इस्तेमाल करना
- carelessly अलग BSON types के numbers compare करना
चैप्टर सारांश
- BSON extra types वाला binary JSON है
- Date, ObjectId, Int32, Int64, Decimal128 add करता है
- Scan और traverse करने में fast
- Tools में extended JSON की तरह दिखता है
🔒
Chapter Quiz — Complete all 7 topics to unlock
0/7 topics done
Complete these topics first: