forked from mongodb/bsonspec.org
-
Notifications
You must be signed in to change notification settings - Fork 0
/
faq.html
89 lines (77 loc) · 2.97 KB
/
faq.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<html>
<body>
<h2 class="nojs">FAQ</h2>
<div class="info" id="faq">
<h3>What is the point of BSON when it is no smaller than
JSON in some cases?</h3>
<p>BSON is designed to be efficient in space, but in some
cases is not much more efficient than JSON. In some cases
BSON uses even more space than JSON. The reason for this
is another of the BSON design goals: traversability. BSON
adds some "extra" information to documents, like length of
strings and subobjects. This makes traversal faster.
</p>
<p>BSON is also designed to be fast to encode and
decode. For example, integers are stored as 32 (or 64) bit
integers, so they don't need to be parsed to and from
text. This uses more space than JSON for small integers,
but is much faster to parse.</p>
<p>In addition to compactness, BSON adds additional data
types unavailable in JSON, notably the BinData and
Date data types.</p>
<h3>What is a <tt>.bson</tt> file?</h3>
BSON files (by convention, using "<tt>.bson</tt>"
extension) contain zero or more BSON documents
written contiguously to a flat file. For example, the
MongoDB <tt>mongodump</tt>
utility outputs BSON files. The <a href="https://www.github.com/dwight/bsontools">bsontools</a>
utilities manipulate BSON files.
<h3>Where can I get more help/infomation?</h3>
<p>The best place to ask questions about BSON is on
the <a href="http://groups.google.com/group/bson">BSON
mailing list</a>.
See also <a href="https://www.mongodb.com/json-and-bson">JSON and BSON white paper.</a></p>
<h3>How can I contribute or make fixes to this site?</h3>
<p>The best way to contribute to this site is to
fork <a href="http://github.com/mongodb/bsonspec.org">the
project</a> and send us a pull request.</p>
</div>
<h2>Examples</h2>
<div>
<p>The following are some example documents (in JavaScript
/ Python style syntax) and their corresponding BSON
representations.</p>
<table>
<tr>
<td>
<pre>
{"hello": "world"}
</pre>
</td>
<td> → </td>
<td><pre>
\x16\x00\x00\x00 // total document size
\x02 // 0x02 = type String
hello\x00 // field name
\x06\x00\x00\x00world\x00 // field value
\x00 // 0x00 = type EOO ('end of object')
</pre></td>
</tr><tr>
<td><pre>
{"BSON": ["awesome", 5.05, 1986]}
</pre></td>
<td> → </td>
<td><pre>
\x31\x00\x00\x00
\x04BSON\x00
\x26\x00\x00\x00
\x02\x30\x00\x08\x00\x00\x00awesome\x00
\x01\x31\x00\x33\x33\x33\x33\x33\x33\x14\x40
\x10\x32\x00\xc2\x07\x00\x00
\x00
\x00
</pre></td>
</tr></table>
</div>
</body>
</html>