-
Notifications
You must be signed in to change notification settings - Fork 902
/
Copy pathclient_bulk_write_models.go
318 lines (271 loc) · 12.4 KB
/
client_bulk_write_models.go
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
// Copyright (C) MongoDB, Inc. 2024-present.
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may
// not use this file except in compliance with the License. You may obtain
// a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
package mongo
import (
"go.mongodb.org/mongo-driver/v2/mongo/options"
)
// ClientWriteModel is an interface implemented by models that can be used in a client-level BulkWrite operation. Each
// ClientWriteModel represents a write.
//
// This interface is implemented by ClientDeleteOneModel, ClientDeleteManyModel, ClientInsertOneModel,
// ClientReplaceOneModel, ClientUpdateOneModel, and ClientUpdateManyModel. Custom implementations of this interface must
// not be used.
type ClientWriteModel interface {
clientWriteModel()
}
// ClientInsertOneModel is used to insert a single document in a client-level BulkWrite operation.
//
// See corresponding setter methods for documentation.
type ClientInsertOneModel struct {
Document interface{}
}
// NewClientInsertOneModel creates a new ClientInsertOneModel.
func NewClientInsertOneModel() *ClientInsertOneModel {
return &ClientInsertOneModel{}
}
func (*ClientInsertOneModel) clientWriteModel() {}
// SetDocument specifies the document to be inserted. The document cannot be nil. If it does not have an _id field when
// transformed into BSON, one will be added automatically to the marshalled document. The original document will not be
// modified.
func (iom *ClientInsertOneModel) SetDocument(doc interface{}) *ClientInsertOneModel {
iom.Document = doc
return iom
}
// ClientUpdateOneModel is used to update at most one document in a client-level BulkWrite operation.
//
// See corresponding setter methods for documentation.
type ClientUpdateOneModel struct {
Collation *options.Collation
Upsert *bool
Filter interface{}
Update interface{}
ArrayFilters []interface{}
Hint interface{}
Sort interface{}
}
// NewClientUpdateOneModel creates a new ClientUpdateOneModel.
func NewClientUpdateOneModel() *ClientUpdateOneModel {
return &ClientUpdateOneModel{}
}
func (*ClientUpdateOneModel) clientWriteModel() {}
// SetHint specifies the index to use for the operation. This should either be the index name as a string or the index
// specification as a document. The default value is nil, which means that no hint will be sent.
func (uom *ClientUpdateOneModel) SetHint(hint interface{}) *ClientUpdateOneModel {
uom.Hint = hint
return uom
}
// SetFilter specifies a filter to use to select the document to update. The filter must be a document containing query
// operators. It cannot be nil. If the filter matches multiple documents, one will be selected from the matching
// documents.
func (uom *ClientUpdateOneModel) SetFilter(filter interface{}) *ClientUpdateOneModel {
uom.Filter = filter
return uom
}
// SetUpdate specifies the modifications to be made to the selected document. The value must be a document containing
// update operators (https://www.mongodb.com/docs/manual/reference/operator/update/). It cannot be nil or empty.
func (uom *ClientUpdateOneModel) SetUpdate(update interface{}) *ClientUpdateOneModel {
uom.Update = update
return uom
}
// SetArrayFilters specifies a set of filters to determine which elements should be modified when updating an array
// field.
func (uom *ClientUpdateOneModel) SetArrayFilters(filters []interface{}) *ClientUpdateOneModel {
uom.ArrayFilters = filters
return uom
}
// SetCollation specifies a collation to use for string comparisons. The default is nil, meaning no collation will be
// used.
func (uom *ClientUpdateOneModel) SetCollation(collation *options.Collation) *ClientUpdateOneModel {
uom.Collation = collation
return uom
}
// SetUpsert specifies whether or not a new document should be inserted if no document matching the filter is found. If
// an upsert is performed, the _id of the upserted document can be retrieved from the UpdateResults field of the
// ClientBulkWriteResult.
func (uom *ClientUpdateOneModel) SetUpsert(upsert bool) *ClientUpdateOneModel {
uom.Upsert = &upsert
return uom
}
// SetSort specifies which document the operation updates if the query matches multiple documents. The first document
// matched by the sort order will be updated. This option is only valid for MongoDB versions >= 8.0. The sort parameter
// is evaluated sequentially, so the driver will return an error if it is a multi-key map (which is unordeded). The
// default value is nil.
func (uom *ClientUpdateOneModel) SetSort(sort interface{}) *ClientUpdateOneModel {
uom.Sort = sort
return uom
}
// ClientUpdateManyModel is used to update multiple documents in a client-level BulkWrite operation.
//
// See corresponding setter methods for documentation.
type ClientUpdateManyModel struct {
Collation *options.Collation
Upsert *bool
Filter interface{}
Update interface{}
ArrayFilters []interface{}
Hint interface{}
}
// NewClientUpdateManyModel creates a new ClientUpdateManyModel.
func NewClientUpdateManyModel() *ClientUpdateManyModel {
return &ClientUpdateManyModel{}
}
func (*ClientUpdateManyModel) clientWriteModel() {}
// SetHint specifies the index to use for the operation. This should either be the index name as a string or the index
// specification as a document. The default value is nil, which means that no hint will be sent.
func (umm *ClientUpdateManyModel) SetHint(hint interface{}) *ClientUpdateManyModel {
umm.Hint = hint
return umm
}
// SetFilter specifies a filter to use to select documents to update. The filter must be a document containing query
// operators. It cannot be nil.
func (umm *ClientUpdateManyModel) SetFilter(filter interface{}) *ClientUpdateManyModel {
umm.Filter = filter
return umm
}
// SetUpdate specifies the modifications to be made to the selected documents. The value must be a document containing
// update operators (https://www.mongodb.com/docs/manual/reference/operator/update/). It cannot be nil or empty.
func (umm *ClientUpdateManyModel) SetUpdate(update interface{}) *ClientUpdateManyModel {
umm.Update = update
return umm
}
// SetArrayFilters specifies a set of filters to determine which elements should be modified when updating an array
// field.
func (umm *ClientUpdateManyModel) SetArrayFilters(filters []interface{}) *ClientUpdateManyModel {
umm.ArrayFilters = filters
return umm
}
// SetCollation specifies a collation to use for string comparisons. The default is nil, meaning no collation will be
// used.
func (umm *ClientUpdateManyModel) SetCollation(collation *options.Collation) *ClientUpdateManyModel {
umm.Collation = collation
return umm
}
// SetUpsert specifies whether or not a new document should be inserted if no document matching the filter is found. If
// an upsert is performed, the _id of the upserted document can be retrieved from the UpdateResults field of the
// ClientBulkWriteResult.
func (umm *ClientUpdateManyModel) SetUpsert(upsert bool) *ClientUpdateManyModel {
umm.Upsert = &upsert
return umm
}
// ClientReplaceOneModel is used to replace at most one document in a client-level BulkWrite operation.
//
// See corresponding setter methods for documentation.
type ClientReplaceOneModel struct {
Collation *options.Collation
Upsert *bool
Filter interface{}
Replacement interface{}
Hint interface{}
Sort interface{}
}
// NewClientReplaceOneModel creates a new ClientReplaceOneModel.
func NewClientReplaceOneModel() *ClientReplaceOneModel {
return &ClientReplaceOneModel{}
}
func (*ClientReplaceOneModel) clientWriteModel() {}
// SetHint specifies the index to use for the operation. This should either be the index name as a string or the index
// specification as a document. The default value is nil, which means that no hint will be sent.
func (rom *ClientReplaceOneModel) SetHint(hint interface{}) *ClientReplaceOneModel {
rom.Hint = hint
return rom
}
// SetFilter specifies a filter to use to select the document to replace. The filter must be a document containing query
// operators. It cannot be nil. If the filter matches multiple documents, one will be selected from the matching
// documents.
func (rom *ClientReplaceOneModel) SetFilter(filter interface{}) *ClientReplaceOneModel {
rom.Filter = filter
return rom
}
// SetReplacement specifies a document that will be used to replace the selected document. It cannot be nil and cannot
// contain any update operators (https://www.mongodb.com/docs/manual/reference/operator/update/).
func (rom *ClientReplaceOneModel) SetReplacement(rep interface{}) *ClientReplaceOneModel {
rom.Replacement = rep
return rom
}
// SetCollation specifies a collation to use for string comparisons. The default is nil, meaning no collation will be
// used.
func (rom *ClientReplaceOneModel) SetCollation(collation *options.Collation) *ClientReplaceOneModel {
rom.Collation = collation
return rom
}
// SetUpsert specifies whether or not the replacement document should be inserted if no document matching the filter is
// found. If an upsert is performed, the _id of the upserted document can be retrieved from the UpdateResults field of the
// BulkWriteResult.
func (rom *ClientReplaceOneModel) SetUpsert(upsert bool) *ClientReplaceOneModel {
rom.Upsert = &upsert
return rom
}
// SetSort specifies which document the operation replaces if the query matches multiple documents. The first document
// matched by the sort order will be replaced. This option is only valid for MongoDB versions >= 8.0. The sort parameter
// is evaluated sequentially, so the driver will return an error if it is a multi-key map (which is unordeded). The
// default value is nil.
func (rom *ClientReplaceOneModel) SetSort(sort interface{}) *ClientReplaceOneModel {
rom.Sort = sort
return rom
}
// ClientDeleteOneModel is used to delete at most one document in a client-level BulkWriteOperation.
//
// See corresponding setter methods for documentation.
type ClientDeleteOneModel struct {
Filter interface{}
Collation *options.Collation
Hint interface{}
}
// NewClientDeleteOneModel creates a new ClientDeleteOneModel.
func NewClientDeleteOneModel() *ClientDeleteOneModel {
return &ClientDeleteOneModel{}
}
func (*ClientDeleteOneModel) clientWriteModel() {}
// SetFilter specifies a filter to use to select the document to delete. The filter must be a document containing query
// operators. It cannot be nil. If the filter matches multiple documents, one will be selected from the matching
// documents.
func (dom *ClientDeleteOneModel) SetFilter(filter interface{}) *ClientDeleteOneModel {
dom.Filter = filter
return dom
}
// SetCollation specifies a collation to use for string comparisons. The default is nil, meaning no collation will be
// used.
func (dom *ClientDeleteOneModel) SetCollation(collation *options.Collation) *ClientDeleteOneModel {
dom.Collation = collation
return dom
}
// SetHint specifies the index to use for the operation. This should either be the index name as a string or the index
// specification as a document. The default value is nil, which means that no hint will be sent.
func (dom *ClientDeleteOneModel) SetHint(hint interface{}) *ClientDeleteOneModel {
dom.Hint = hint
return dom
}
// ClientDeleteManyModel is used to delete multiple documents in a client-level BulkWrite operation.
//
// See corresponding setter methods for documentation.
type ClientDeleteManyModel struct {
Filter interface{}
Collation *options.Collation
Hint interface{}
}
// NewClientDeleteManyModel creates a new ClientDeleteManyModel.
func NewClientDeleteManyModel() *ClientDeleteManyModel {
return &ClientDeleteManyModel{}
}
func (*ClientDeleteManyModel) clientWriteModel() {}
// SetFilter specifies a filter to use to select documents to delete. The filter must be a document containing query
// operators. It cannot be nil.
func (dmm *ClientDeleteManyModel) SetFilter(filter interface{}) *ClientDeleteManyModel {
dmm.Filter = filter
return dmm
}
// SetCollation specifies a collation to use for string comparisons. The default is nil, meaning no collation will be
// used.
func (dmm *ClientDeleteManyModel) SetCollation(collation *options.Collation) *ClientDeleteManyModel {
dmm.Collation = collation
return dmm
}
// SetHint specifies the index to use for the operation. This should either be the index name as a string or the index
// specification as a document. The default value is nil, which means that no hint will be sent.
func (dmm *ClientDeleteManyModel) SetHint(hint interface{}) *ClientDeleteManyModel {
dmm.Hint = hint
return dmm
}