Commit bc03cee
committed
Redesign Document, Array, Element, and Value types
Migration Notes:
The Document, Element, Value, and Array types have been redesign and
rewritten. They have been renamed Doc, Elem, Val, and Arr respectively.
And additional type, MDoc, has been created.
The Value type no longer stores values as a slice of bytes,
instead opting for a compact 32byte representation that stores values
closer to native Go types. An empty Value is equivalent to a BSON Null.
All of the methods in this package will treat Value{} and
bson.Null() as the same.
The Element type is much simpler and adds a key to a Value.
The Document and Array types have been simplified, removing many of
their methods, and making them conceptually two different types, instead
of building an Array on top of a Document. Their methods have also been
updated to handle easier usage of Element and Value instances.
The constructors have been removed and replaced with a simpler
construction system that uses functions. There is a symmetry between
these functions and the methods on the Value type. The input to the
constructor matches the output of the Value method, for example this is
valid: bson.Double(val.Double()).
The BSON primitive types have been moved from the bson package to a new
package called primitive. The types that were (briefly) called
*Primitive are now call primitive.*, e.g.
RegexPrimitive->primitive.Regex.
The Doc and MDoc types are functionally equivalents of D and M, but with
much higher type safety. Because Doc, MDoc, Arr, Elem, and Val form a
closed systems, and because it's not possible to create an invalid Val
type, Doc, MDoc, and Arr never return errors when Marshaling to BSON.
Both Doc and MDoc have depth traversal capabilities, so looking up a key
thats several subdocuments deep can be done with a single method call,
and in the case of MDoc can be done so in a higher performance manner.
When migrating from Document to Doc, users should ensure they reassign
the return of Append, Prepend, and Set to the doc. With Document, one
could call Append and it would modify the original document, the new Doc
type does not operate in this manner and operates similar to a regular
slice.
GODRIVER-413
GODRIVER-610
Change-Id: I353a83b7c8f8c5fa0c2552de9ff8bc78d55c50bc1 parent 5367196 commit bc03cee
File tree
165 files changed
+5826
-13287
lines changed- benchmark
- bson
- bsonrw/bsonrwtest
- primitive
- core
- auth
- command
- connection
- dispatch
- event
- examples
- count
- workload
- integration
- readconcern
- result
- session
- topology
- wiremessage
- writeconcern
- examples/documentation_examples
- internal
- testutil
- mongo
- gridfs
- options
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
165 files changed
+5826
-13287
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
27 | | - | |
| 27 | + | |
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
32 | | - | |
| 32 | + | |
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
38 | | - | |
| 38 | + | |
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
| |||
54 | 54 | | |
55 | 55 | | |
56 | 56 | | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
51 | | - | |
| 51 | + | |
52 | 52 | | |
53 | 53 | | |
54 | 54 | | |
55 | | - | |
| 55 | + | |
56 | 56 | | |
57 | 57 | | |
58 | 58 | | |
| |||
73 | 73 | | |
74 | 74 | | |
75 | 75 | | |
76 | | - | |
| 76 | + | |
77 | 77 | | |
78 | 78 | | |
79 | 79 | | |
80 | 80 | | |
81 | | - | |
82 | | - | |
83 | | - | |
84 | | - | |
85 | | - | |
| 81 | + | |
86 | 82 | | |
87 | 83 | | |
88 | 84 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
49 | | - | |
| 49 | + | |
50 | 50 | | |
51 | 51 | | |
52 | 52 | | |
| |||
108 | 108 | | |
109 | 109 | | |
110 | 110 | | |
111 | | - | |
| 111 | + | |
112 | 112 | | |
113 | 113 | | |
114 | 114 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
49 | 49 | | |
50 | 50 | | |
51 | 51 | | |
52 | | - | |
| 52 | + | |
53 | 53 | | |
54 | 54 | | |
55 | 55 | | |
| |||
88 | 88 | | |
89 | 89 | | |
90 | 90 | | |
91 | | - | |
| 91 | + | |
92 | 92 | | |
93 | 93 | | |
94 | 94 | | |
| |||
100 | 100 | | |
101 | 101 | | |
102 | 102 | | |
103 | | - | |
| 103 | + | |
104 | 104 | | |
105 | 105 | | |
106 | 106 | | |
| |||
135 | 135 | | |
136 | 136 | | |
137 | 137 | | |
138 | | - | |
| 138 | + | |
139 | 139 | | |
140 | 140 | | |
141 | 141 | | |
| |||
0 commit comments