You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+55-13Lines changed: 55 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -100,15 +100,15 @@ it will be written to database, as:
100
100
101
101
While using the `Mongo.Encoder` protocol give you the possibility to encode your structs into maps the opposite way to decode those maps into structs is missing. To handle it you can use the `Mongo.Collection` which provides some boilerplate code for a better support of structs while using the MongoDB driver
102
102
103
-
* automatic load and dump function
104
-
* reflection functions
105
-
* type specification
106
-
* support for embedding one and many structs
107
-
* support for `after load` function
108
-
* support for `before dump` function
109
-
* support for id generation
110
-
* support for default values
111
-
* support for derived values
103
+
- automatic load and dump function
104
+
- reflection functions
105
+
- type specification
106
+
- support for embedding one and many structs
107
+
- support for `after load` function
108
+
- support for `before dump` function
109
+
- support for id generation
110
+
- support for default values
111
+
- support for derived values
112
112
113
113
When using the MongoDB driver only maps and keyword lists are used to represent documents.
114
114
If you would prefer to use structs instead of the maps to give the document a stronger meaning or to emphasize
@@ -141,11 +141,12 @@ converts the atom keys into strings (Or use the `Mongo.Encode` protocol)
141
141
iex>Map.drop(label, [:__struct__])
142
142
%{color::red, name:"warning"}
143
143
```
144
+
144
145
If you use nested structures, the work becomes a bit more complex. In this case, you have to use the inner structures
145
146
convert manually, too. If you take a closer look at the necessary work, two basic functions can be derived:
146
147
147
-
*`load` Conversion of the map into a struct.
148
-
*`dump` Conversion of the struct into a map.
148
+
-`load` Conversion of the map into a struct.
149
+
-`dump` Conversion of the struct into a map.
149
150
150
151
`Mongo.Collection` provides the necessary macros to automate this boilerplate code. The above example can be rewritten as follows:
0 commit comments