forked from mongodb/mongo-csharp-driver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCreateCollectionOptions.cs
334 lines (306 loc) · 11.5 KB
/
CreateCollectionOptions.cs
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
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
/* Copyright 2010-present MongoDB Inc.
*
* 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
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
using System;
using MongoDB.Bson;
using MongoDB.Bson.Serialization;
namespace MongoDB.Driver
{
/// <summary>
/// Options for creating a collection.
/// </summary>
public class CreateCollectionOptions
{
// fields
private bool? _autoIndexId;
private bool? _capped;
private ChangeStreamPreAndPostImagesOptions _changeStreamPreAndPostImagesOptions;
private Collation _collation;
private BsonDocument _encryptedFields;
private TimeSpan? _expireAfter;
private IndexOptionDefaults _indexOptionDefaults;
private long? _maxDocuments;
private long? _maxSize;
private bool? _noPadding;
private BsonDocument _storageEngine;
private TimeSeriesOptions _timeSeriesOptions;
private bool? _usePowerOf2Sizes;
private IBsonSerializerRegistry _serializerRegistry;
private DocumentValidationAction? _validationAction;
private DocumentValidationLevel? _validationLevel;
// properties
/// <summary>
/// Gets or sets the collation.
/// </summary>
public Collation Collation
{
get { return _collation; }
set { _collation = value; }
}
/// <summary>
/// Gets or sets a value indicating whether to automatically create an index on the _id.
/// </summary>
[Obsolete("AutoIndexId has been deprecated since server version 3.2.")]
public bool? AutoIndexId
{
get { return _autoIndexId; }
set { _autoIndexId = value; }
}
/// <summary>
/// Gets or sets a value indicating whether the collection is capped.
/// </summary>
public bool? Capped
{
get { return _capped; }
set { _capped = value; }
}
/// <summary>
/// Gets or sets Gets or sets a change streams pre and post images options.
/// </summary>
public ChangeStreamPreAndPostImagesOptions ChangeStreamPreAndPostImagesOptions
{
get { return _changeStreamPreAndPostImagesOptions; }
set { _changeStreamPreAndPostImagesOptions = value; }
}
/// <summary>
/// Gets or sets encrypted fields.
/// </summary>
public BsonDocument EncryptedFields
{
get { return _encryptedFields; }
set { _encryptedFields = value; }
}
/// <summary>
/// Gets or sets a timespan indicating how long documents in a time series collection should be retained.
/// </summary>
public TimeSpan? ExpireAfter
{
get { return _expireAfter; }
set { _expireAfter = value; }
}
/// <summary>
/// Gets or sets the index option defaults.
/// </summary>
/// <value>
/// The index option defaults.
/// </value>
public IndexOptionDefaults IndexOptionDefaults
{
get { return _indexOptionDefaults; }
set { _indexOptionDefaults = value; }
}
/// <summary>
/// Gets or sets the maximum number of documents (used with capped collections).
/// </summary>
public long? MaxDocuments
{
get { return _maxDocuments; }
set { _maxDocuments = value; }
}
/// <summary>
/// Gets or sets the maximum size of the collection (used with capped collections).
/// </summary>
public long? MaxSize
{
get { return _maxSize; }
set { _maxSize = value; }
}
/// <summary>
/// Gets or sets whether padding should not be used.
/// </summary>
public bool? NoPadding
{
get { return _noPadding; }
set { _noPadding = value; }
}
/// <summary>
/// Gets or sets the serializer registry.
/// </summary>
public IBsonSerializerRegistry SerializerRegistry
{
get { return _serializerRegistry; }
set { _serializerRegistry = value; }
}
/// <summary>
/// Gets or sets the storage engine options.
/// </summary>
public BsonDocument StorageEngine
{
get { return _storageEngine; }
set { _storageEngine = value; }
}
/// <summary>
/// Gets or sets the <see cref="TimeSeriesOptions"/> to use when creating a time series collection.
/// </summary>
public TimeSeriesOptions TimeSeriesOptions
{
get { return _timeSeriesOptions; }
set { _timeSeriesOptions = value; }
}
/// <summary>
/// Gets or sets a value indicating whether to use power of 2 sizes.
/// </summary>
public bool? UsePowerOf2Sizes
{
get { return _usePowerOf2Sizes; }
set { _usePowerOf2Sizes = value; }
}
/// <summary>
/// Gets or sets the validation action.
/// </summary>
/// <value>
/// The validation action.
/// </value>
public DocumentValidationAction? ValidationAction
{
get { return _validationAction; }
set { _validationAction = value; }
}
/// <summary>
/// Gets or sets the validation level.
/// </summary>
/// <value>
/// The validation level.
/// </value>
public DocumentValidationLevel? ValidationLevel
{
get { return _validationLevel; }
set { _validationLevel = value; }
}
internal virtual CreateCollectionOptions Clone() =>
new CreateCollectionOptions
{
_autoIndexId = _autoIndexId,
_capped = _capped,
_changeStreamPreAndPostImagesOptions = _changeStreamPreAndPostImagesOptions,
_collation = _collation,
_encryptedFields = _encryptedFields,
_expireAfter = _expireAfter,
_indexOptionDefaults = _indexOptionDefaults,
_maxDocuments = _maxDocuments,
_maxSize = _maxSize,
_noPadding = _noPadding,
_serializerRegistry = _serializerRegistry,
_storageEngine = _storageEngine,
_timeSeriesOptions = _timeSeriesOptions,
_usePowerOf2Sizes = _usePowerOf2Sizes,
_validationAction = _validationAction,
_validationLevel = _validationLevel
};
}
/// <summary>
/// Options for creating a collection.
/// </summary>
/// <typeparam name="TDocument">The type of the document.</typeparam>
public sealed class CreateCollectionOptions<TDocument> : CreateCollectionOptions
{
#region static
// internal static methods
/// <summary>
/// Coerces a generic CreateCollectionOptions{TDocument} from a non-generic CreateCollectionOptions.
/// </summary>
/// <param name="options">The options.</param>
/// <returns>The generic options.</returns>
internal static CreateCollectionOptions<TDocument> CoercedFrom(CreateCollectionOptions options)
{
if (options == null)
{
return null;
}
if (options.GetType() == typeof(CreateCollectionOptions))
{
#pragma warning disable 618
return new CreateCollectionOptions<TDocument>
{
AutoIndexId = options.AutoIndexId,
Capped = options.Capped,
Collation = options.Collation,
ChangeStreamPreAndPostImagesOptions = options.ChangeStreamPreAndPostImagesOptions,
EncryptedFields = options.EncryptedFields,
ExpireAfter = options.ExpireAfter,
IndexOptionDefaults = options.IndexOptionDefaults,
MaxDocuments = options.MaxDocuments,
MaxSize = options.MaxSize,
NoPadding = options.NoPadding,
SerializerRegistry = options.SerializerRegistry,
StorageEngine = options.StorageEngine,
TimeSeriesOptions = options.TimeSeriesOptions,
UsePowerOf2Sizes = options.UsePowerOf2Sizes,
ValidationAction = options.ValidationAction,
ValidationLevel = options.ValidationLevel
};
#pragma warning restore
}
return (CreateCollectionOptions<TDocument>)options;
}
#endregion
// private fields
private ClusteredIndexOptions<TDocument> _clusteredIndex;
private IBsonSerializer<TDocument> _documentSerializer;
private FilterDefinition<TDocument> _validator;
// public properties
/// <summary>
/// Gets or sets the <see cref="ClusteredIndexOptions{TDocument}"/>.
/// </summary>
public ClusteredIndexOptions<TDocument> ClusteredIndex
{
get { return _clusteredIndex; }
set { _clusteredIndex = value; }
}
/// <summary>
/// Gets or sets the document serializer.
/// </summary>
public IBsonSerializer<TDocument> DocumentSerializer
{
get { return _documentSerializer; }
set { _documentSerializer = value; }
}
/// <summary>
/// Gets or sets the validator.
/// </summary>
/// <value>
/// The validator.
/// </value>
public FilterDefinition<TDocument> Validator
{
get { return _validator; }
set { _validator = value; }
}
internal override CreateCollectionOptions Clone() =>
new CreateCollectionOptions<TDocument>
{
#pragma warning disable CS0618 // Type or member is obsolete
AutoIndexId = base.AutoIndexId,
#pragma warning restore CS0618 // Type or member is obsolete
Capped = base.Capped,
ChangeStreamPreAndPostImagesOptions = base.ChangeStreamPreAndPostImagesOptions,
Collation = base.Collation,
EncryptedFields = base.EncryptedFields,
ExpireAfter = base.ExpireAfter,
IndexOptionDefaults = base.IndexOptionDefaults,
MaxDocuments = base.MaxDocuments,
MaxSize = base.MaxSize,
NoPadding = base.NoPadding,
SerializerRegistry = base.SerializerRegistry,
StorageEngine = base.StorageEngine,
TimeSeriesOptions = base.TimeSeriesOptions,
UsePowerOf2Sizes = base.UsePowerOf2Sizes,
ValidationAction = base.ValidationAction,
ValidationLevel = base.ValidationLevel,
_clusteredIndex = _clusteredIndex,
_documentSerializer = _documentSerializer,
_validator = _validator
};
}
}