@@ -10,12 +10,16 @@ import (
10
10
"go.mongodb.org/mongo-driver/mongo/options"
11
11
)
12
12
13
- // WriteModel is the interface satisfied by all models for bulk writes.
13
+ // WriteModel is an interface implemented by models that can be used in a BulkWrite operation. Each WriteModel
14
+ // represents a write.
15
+ //
16
+ // This interface is implemented by InsertOneModel, DeleteOneModel, DeleteManyModel, ReplaceOneModel, UpdateOneModel,
17
+ // and UpdateManyModel. Custom implementations of this interface must not be used.
14
18
type WriteModel interface {
15
19
writeModel ()
16
20
}
17
21
18
- // InsertOneModel is the write model for insert operations .
22
+ // InsertOneModel is used to insert a single document in a BulkWrite operation .
19
23
type InsertOneModel struct {
20
24
Document interface {}
21
25
}
@@ -25,15 +29,17 @@ func NewInsertOneModel() *InsertOneModel {
25
29
return & InsertOneModel {}
26
30
}
27
31
28
- // SetDocument sets the BSON document for the InsertOneModel.
32
+ // SetDocument specifies the document to be inserted. The document cannot be nil. If it does not have an _id field when
33
+ // transformed into BSON, one will be added automatically to the marshalled document. The original document will not be
34
+ // modified.
29
35
func (iom * InsertOneModel ) SetDocument (doc interface {}) * InsertOneModel {
30
36
iom .Document = doc
31
37
return iom
32
38
}
33
39
34
40
func (* InsertOneModel ) writeModel () {}
35
41
36
- // DeleteOneModel is the write model for delete operations .
42
+ // DeleteOneModel is used to delete at most one document in a BulkWriteOperation .
37
43
type DeleteOneModel struct {
38
44
Filter interface {}
39
45
Collation * options.Collation
@@ -44,21 +50,24 @@ func NewDeleteOneModel() *DeleteOneModel {
44
50
return & DeleteOneModel {}
45
51
}
46
52
47
- // SetFilter sets the filter for the DeleteOneModel.
53
+ // SetFilter specifies a filter to use to select the document to delete. The filter must be a document containing query
54
+ // operators. It cannot be nil. If the filter matches multiple documents, one will be selected from the matching
55
+ // documents.
48
56
func (dom * DeleteOneModel ) SetFilter (filter interface {}) * DeleteOneModel {
49
57
dom .Filter = filter
50
58
return dom
51
59
}
52
60
53
- // SetCollation sets the collation for the DeleteOneModel.
61
+ // SetCollation specifies a collation to use for string comparisons. The default is nil, meaning no collation will be
62
+ // used.
54
63
func (dom * DeleteOneModel ) SetCollation (collation * options.Collation ) * DeleteOneModel {
55
64
dom .Collation = collation
56
65
return dom
57
66
}
58
67
59
68
func (* DeleteOneModel ) writeModel () {}
60
69
61
- // DeleteManyModel is the write model for deleteMany operations .
70
+ // DeleteManyModel is used to delete multiple documents in a BulkWrite operation .
62
71
type DeleteManyModel struct {
63
72
Filter interface {}
64
73
Collation * options.Collation
@@ -69,21 +78,23 @@ func NewDeleteManyModel() *DeleteManyModel {
69
78
return & DeleteManyModel {}
70
79
}
71
80
72
- // SetFilter sets the filter for the DeleteManyModel.
81
+ // SetFilter specifies a filter to use to select documents to delete. The filter must be a document containing query
82
+ // operators. It cannot be nil.
73
83
func (dmm * DeleteManyModel ) SetFilter (filter interface {}) * DeleteManyModel {
74
84
dmm .Filter = filter
75
85
return dmm
76
86
}
77
87
78
- // SetCollation sets the collation for the DeleteManyModel.
88
+ // SetCollation specifies a collation to use for string comparisons. The default is nil, meaning no collation will be
89
+ // used.
79
90
func (dmm * DeleteManyModel ) SetCollation (collation * options.Collation ) * DeleteManyModel {
80
91
dmm .Collation = collation
81
92
return dmm
82
93
}
83
94
84
95
func (* DeleteManyModel ) writeModel () {}
85
96
86
- // ReplaceOneModel is the write model for replace operations .
97
+ // ReplaceOneModel is used to replace at most one document in a BulkWrite operation .
87
98
type ReplaceOneModel struct {
88
99
Collation * options.Collation
89
100
Upsert * bool
@@ -96,33 +107,39 @@ func NewReplaceOneModel() *ReplaceOneModel {
96
107
return & ReplaceOneModel {}
97
108
}
98
109
99
- // SetFilter sets the filter for the ReplaceOneModel.
110
+ // SetFilter specifies a filter to use to select the document to replace. The filter must be a document containing query
111
+ // operators. It cannot be nil. If the filter matches multiple documents, one will be selected from the matching
112
+ // documents.
100
113
func (rom * ReplaceOneModel ) SetFilter (filter interface {}) * ReplaceOneModel {
101
114
rom .Filter = filter
102
115
return rom
103
116
}
104
117
105
- // SetReplacement sets the replacement document for the ReplaceOneModel.
118
+ // SetReplacement specifies a document that will be used to replace the selected document. It cannot be nil and cannot
119
+ // contain any update operators (https://docs.mongodb.com/manual/reference/operator/update/).
106
120
func (rom * ReplaceOneModel ) SetReplacement (rep interface {}) * ReplaceOneModel {
107
121
rom .Replacement = rep
108
122
return rom
109
123
}
110
124
111
- // SetCollation sets the collation for the ReplaceOneModel.
125
+ // SetCollation specifies a collation to use for string comparisons. The default is nil, meaning no collation will be
126
+ // used.
112
127
func (rom * ReplaceOneModel ) SetCollation (collation * options.Collation ) * ReplaceOneModel {
113
128
rom .Collation = collation
114
129
return rom
115
130
}
116
131
117
- // SetUpsert specifies if a new document should be created if no document matches the query.
132
+ // SetUpsert specifies whether or not the replacement document should be inserted if no document matching the filter is
133
+ // found. If an upsert is performed, the _id of the upserted document can be retrieved from the UpsertedIDs field of the
134
+ // BulkWriteResult.
118
135
func (rom * ReplaceOneModel ) SetUpsert (upsert bool ) * ReplaceOneModel {
119
136
rom .Upsert = & upsert
120
137
return rom
121
138
}
122
139
123
140
func (* ReplaceOneModel ) writeModel () {}
124
141
125
- // UpdateOneModel is the write model for update operations .
142
+ // UpdateOneModel is used to update at most one document in a BulkWrite operation .
126
143
type UpdateOneModel struct {
127
144
Collation * options.Collation
128
145
Upsert * bool
@@ -136,39 +153,46 @@ func NewUpdateOneModel() *UpdateOneModel {
136
153
return & UpdateOneModel {}
137
154
}
138
155
139
- // SetFilter sets the filter for the UpdateOneModel.
156
+ // SetFilter specifies a filter to use to select the document to update. The filter must be a document containing query
157
+ // operators. It cannot be nil. If the filter matches multiple documents, one will be selected from the matching
158
+ // documents.
140
159
func (uom * UpdateOneModel ) SetFilter (filter interface {}) * UpdateOneModel {
141
160
uom .Filter = filter
142
161
return uom
143
162
}
144
163
145
- // SetUpdate sets the update document for the UpdateOneModel.
164
+ // SetUpdate specifies the modifications to be made to the selected document. The value must be a document containing
165
+ // update operators (https://docs.mongodb.com/manual/reference/operator/update/). It cannot be nil or empty.
146
166
func (uom * UpdateOneModel ) SetUpdate (update interface {}) * UpdateOneModel {
147
167
uom .Update = update
148
168
return uom
149
169
}
150
170
151
- // SetArrayFilters specifies a set of filters specifying to which array elements an update should apply.
171
+ // SetArrayFilters specifies a set of filters to determine which elements should be modified when updating an array
172
+ // field.
152
173
func (uom * UpdateOneModel ) SetArrayFilters (filters options.ArrayFilters ) * UpdateOneModel {
153
174
uom .ArrayFilters = & filters
154
175
return uom
155
176
}
156
177
157
- // SetCollation sets the collation for the UpdateOneModel.
178
+ // SetCollation specifies a collation to use for string comparisons. The default is nil, meaning no collation will be
179
+ // used.
158
180
func (uom * UpdateOneModel ) SetCollation (collation * options.Collation ) * UpdateOneModel {
159
181
uom .Collation = collation
160
182
return uom
161
183
}
162
184
163
- // SetUpsert specifies if a new document should be created if no document matches the query.
185
+ // SetUpsert specifies whether or not a new document should be inserted if no document matching the filter is found. If
186
+ // an upsert is performed, the _id of the upserted document can be retrieved from the UpsertedIDs field of the
187
+ // BulkWriteResult.
164
188
func (uom * UpdateOneModel ) SetUpsert (upsert bool ) * UpdateOneModel {
165
189
uom .Upsert = & upsert
166
190
return uom
167
191
}
168
192
169
193
func (* UpdateOneModel ) writeModel () {}
170
194
171
- // UpdateManyModel is the write model for updateMany operations .
195
+ // UpdateManyModel is used to update multiple documents in a BulkWrite operation .
172
196
type UpdateManyModel struct {
173
197
Collation * options.Collation
174
198
Upsert * bool
@@ -182,31 +206,37 @@ func NewUpdateManyModel() *UpdateManyModel {
182
206
return & UpdateManyModel {}
183
207
}
184
208
185
- // SetFilter sets the filter for the UpdateManyModel.
209
+ // SetFilter specifies a filter to use to select documents to update. The filter must be a document containing query
210
+ // operators. It cannot be nil.
186
211
func (umm * UpdateManyModel ) SetFilter (filter interface {}) * UpdateManyModel {
187
212
umm .Filter = filter
188
213
return umm
189
214
}
190
215
191
- // SetUpdate sets the update document for the UpdateManyModel.
216
+ // SetUpdate specifies the modifications to be made to the selected documents. The value must be a document containing
217
+ // update operators (https://docs.mongodb.com/manual/reference/operator/update/). It cannot be nil or empty.
192
218
func (umm * UpdateManyModel ) SetUpdate (update interface {}) * UpdateManyModel {
193
219
umm .Update = update
194
220
return umm
195
221
}
196
222
197
- // SetArrayFilters specifies a set of filters specifying to which array elements an update should apply.
223
+ // SetArrayFilters specifies a set of filters to determine which elements should be modified when updating an array
224
+ // field.
198
225
func (umm * UpdateManyModel ) SetArrayFilters (filters options.ArrayFilters ) * UpdateManyModel {
199
226
umm .ArrayFilters = & filters
200
227
return umm
201
228
}
202
229
203
- // SetCollation sets the collation for the UpdateManyModel.
230
+ // SetCollation specifies a collation to use for string comparisons. The default is nil, meaning no collation will be
231
+ // used.
204
232
func (umm * UpdateManyModel ) SetCollation (collation * options.Collation ) * UpdateManyModel {
205
233
umm .Collation = collation
206
234
return umm
207
235
}
208
236
209
- // SetUpsert specifies if a new document should be created if no document matches the query.
237
+ // SetUpsert specifies whether or not a new document should be inserted if no document matching the filter is found. If
238
+ // an upsert is performed, the _id of the upserted document can be retrieved from the UpsertedIDs field of the
239
+ // BulkWriteResult.
210
240
func (umm * UpdateManyModel ) SetUpsert (upsert bool ) * UpdateManyModel {
211
241
umm .Upsert = & upsert
212
242
return umm
0 commit comments