This repository has been archived by the owner on Dec 30, 2020. It is now read-only.
/
MongoCollection.cs
417 lines (378 loc) · 15.1 KB
/
MongoCollection.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
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
using System;
using System.Collections.Generic;
using MongoDB.Configuration;
using MongoDB.Connections;
namespace MongoDB
{
/// <summary>
/// </summary>
public class MongoCollection : IMongoCollection
{
private readonly MongoCollection<Document> _collection;
/// <summary>
/// Initializes a new instance of the <see cref = "MongoCollection<T>" /> class.
/// </summary>
/// <param name = "configuration">The configuration.</param>
/// <param name = "connection">The connection.</param>
/// <param name = "databaseName">Name of the database.</param>
/// <param name = "name">The name.</param>
internal MongoCollection(MongoConfiguration configuration, Connection connection, string databaseName, string name)
{
//Todo: add public constrcutor for users to call
_collection = new MongoCollection<Document>(configuration, connection, databaseName, name);
}
/// <summary>
/// Gets the database.
/// </summary>
/// <value>The database.</value>
public IMongoDatabase Database
{
get { return _collection.Database; }
}
/// <summary>
/// Gets the name.
/// </summary>
/// <value>The name.</value>
public string Name
{
get { return _collection.Name; }
}
/// <summary>
/// Gets the name of the database.
/// </summary>
/// <value>The name of the database.</value>
public string DatabaseName
{
get { return _collection.DatabaseName; }
}
/// <summary>
/// Gets the full name.
/// </summary>
/// <value>The full name.</value>
public string FullName
{
get { return _collection.FullName; }
}
/// <summary>
/// Gets the meta data.
/// </summary>
/// <value>The meta data.</value>
public CollectionMetadata Metadata
{
get { return _collection.Metadata; }
}
/// <summary>
/// Finds the one.
/// </summary>
/// <param name = "spec">The spec.</param>
/// <returns></returns>
public Document FindOne(Document spec)
{
return _collection.FindOne(spec);
}
/// <summary>
/// Finds all.
/// </summary>
/// <returns></returns>
public ICursor FindAll()
{
return new Cursor(_collection.FindAll());
}
/// <summary>
/// Finds the specified where.
/// </summary>
/// <param name = "where">The where.</param>
/// <returns></returns>
public ICursor Find(string @where)
{
return new Cursor(_collection.Find(@where));
}
/// <summary>
/// Finds the specified spec.
/// </summary>
/// <param name = "spec">The spec.</param>
/// <returns></returns>
public ICursor Find(Document spec)
{
return new Cursor(_collection.Find(spec));
}
/// <summary>
/// Finds the specified spec.
/// </summary>
/// <param name = "spec">The spec.</param>
/// <param name = "limit">The limit.</param>
/// <param name = "skip">The skip.</param>
/// <returns></returns>
public ICursor Find(Document spec, int limit, int skip)
{
return new Cursor(_collection.Find(spec, limit, skip));
}
/// <summary>
/// Finds the specified spec.
/// </summary>
/// <param name = "spec">The spec.</param>
/// <param name = "limit">The limit.</param>
/// <param name = "skip">The skip.</param>
/// <param name = "fields">The fields.</param>
/// <returns></returns>
public ICursor Find(Document spec, int limit, int skip, Document fields)
{
return new Cursor(_collection.Find(spec, limit, skip, fields));
}
/// <summary>
/// Executes a query and atomically applies a modifier operation to the first document returning the original document
/// by default.
/// </summary>
/// <param name = "document">The document.</param>
/// <param name = "spec"><see cref = "Document" /> to find the document.</param>
/// <returns>A <see cref = "Document" /></returns>
public Document FindAndModify(Document document, Document spec)
{
return _collection.FindAndModify(document, spec);
}
/// <summary>
/// Executes a query and atomically applies a modifier operation to the first document returning the original document
/// by default.
/// </summary>
/// <param name = "document">The document.</param>
/// <param name = "spec"><see cref = "Document" /> to find the document.</param>
/// <param name = "sort"><see cref = "Document" /> containing the names of columns to sort on with the values being the</param>
/// <returns>A <see cref = "Document" /></returns>
/// <see cref = "IndexOrder" />
public Document FindAndModify(Document document, Document spec, Document sort)
{
return _collection.FindAndModify(document, spec, sort);
}
/// <summary>
/// Executes a query and atomically applies a modifier operation to the first document returning the original document
/// by default.
/// </summary>
/// <param name = "document">The document.</param>
/// <param name = "spec"><see cref = "Document" /> to find the document.</param>
/// <param name = "returnNew">if set to <c>true</c> [return new].</param>
/// <returns>A <see cref = "Document" /></returns>
public Document FindAndModify(Document document, Document spec, bool returnNew)
{
return _collection.FindAndModify(document, spec, returnNew);
}
/// <summary>
/// Executes a query and atomically applies a modifier operation to the first document returning the original document
/// by default.
/// </summary>
/// <param name="document">The document.</param>
/// <param name="spec"><see cref="Document"/> to find the document.</param>
/// <param name="sort"><see cref="Document"/> containing the names of columns to sort on with the values being the
/// <see cref="IndexOrder"/></param>
/// <param name="returnNew">if set to <c>true</c> [return new].</param>
/// <returns>A <see cref="Document"/></returns>
public Document FindAndModify(Document document, Document spec, Document sort, bool returnNew)
{
return _collection.FindAndModify(document, spec, sort, null, false, returnNew, false);
}
/// <summary>
/// Executes a query and atomically applies a modifier operation to the first document returning the original document
/// by default.
/// </summary>
/// <param name="document">The document.</param>
/// <param name="spec"><see cref="Document"/> to find the document.</param>
/// <param name="sort"><see cref="Document"/> containing the names of columns to sort on with the values being the
/// <see cref="IndexOrder"/></param>
/// <param name="fields">The fields.</param>
/// <param name="remove">if set to <c>true</c> [remove].</param>
/// <param name="returnNew">if set to <c>true</c> [return new].</param>
/// <param name="upsert">if set to <c>true</c> [upsert].</param>
/// <returns>A <see cref="Document"/></returns>
public Document FindAndModify(Document document, Document spec, Document sort, Document fields, bool remove, bool returnNew, bool upsert)
{
return _collection.FindAndModify(document, spec, sort, fields, remove, returnNew, upsert);
}
/// <summary>
/// Maps the reduce.
/// </summary>
/// <returns></returns>
public MapReduce MapReduce()
{
return _collection.MapReduce();
}
/// <summary>
/// Counts this instance.
/// </summary>
/// <returns></returns>
public long Count()
{
return _collection.Count();
}
/// <summary>
/// Counts the specified spec.
/// </summary>
/// <param name = "spec">The spec.</param>
/// <returns></returns>
public long Count(Document spec)
{
return _collection.Count(spec);
}
/// <summary>
/// Inserts the specified doc.
/// </summary>
/// <param name = "document">The document.</param>
public void Insert(Document document)
{
_collection.Insert(document);
}
/// <summary>
/// Inserts the specified doc.
/// </summary>
/// <param name = "document">The document.</param>
/// <param name = "safemode">if set to <c>true</c> [safemode].</param>
public void Insert(Document document, bool safemode)
{
_collection.Insert(document, safemode);
}
/// <summary>
/// Inserts the specified docs.
/// </summary>
/// <param name = "documents">The docs.</param>
public void Insert(IEnumerable<Document> documents)
{
_collection.Insert(documents);
}
/// <summary>
/// Inserts the specified docs.
/// </summary>
/// <param name = "documents">The docs.</param>
/// <param name = "safemode">if set to <c>true</c> [safemode].</param>
public void Insert(IEnumerable<Document> documents, bool safemode)
{
_collection.Insert(documents, safemode);
}
/// <summary>
/// Deletes the specified selector.
/// </summary>
/// <param name = "selector">The selector.</param>
[Obsolete("Use Remove instead")]
public void Delete(Document selector)
{
_collection.Delete(selector);
}
/// <summary>
/// Removes the specified selector.
/// </summary>
/// <param name = "selector">The selector.</param>
public void Remove(Document selector)
{
_collection.Remove(selector);
}
/// <summary>
/// Deletes the specified selector.
/// </summary>
/// <param name = "selector">The selector.</param>
/// <param name = "safemode">if set to <c>true</c> [safemode].</param>
[Obsolete("Use Remove instead")]
public void Delete(Document selector, bool safemode)
{
_collection.Delete(selector, safemode);
}
/// <summary>
/// Removes the specified selector.
/// </summary>
/// <param name = "selector">The selector.</param>
/// <param name = "safemode">if set to <c>true</c> [safemode].</param>
public void Remove(Document selector, bool safemode)
{
_collection.Remove(selector, safemode);
}
/// <summary>
/// Updates the specified doc.
/// </summary>
/// <param name = "document">The document.</param>
/// <param name = "safemode">if set to <c>true</c> [safemode].</param>
public void Update(Document document, bool safemode)
{
_collection.Save(document, safemode);
}
/// <summary>
/// Updates the specified doc.
/// </summary>
/// <param name = "document">The document.</param>
public void Update(Document document)
{
_collection.Save(document);
}
/// <summary>
/// Updates the specified doc.
/// </summary>
/// <param name = "document">The document.</param>
/// <param name = "selector">The selector.</param>
public void Update(Document document, Document selector)
{
_collection.Update(document, selector);
}
/// <summary>
/// Updates the specified doc.
/// </summary>
/// <param name = "document">The document.</param>
/// <param name = "selector">The selector.</param>
/// <param name = "safemode">if set to <c>true</c> [safemode].</param>
public void Update(Document document, Document selector, bool safemode)
{
_collection.Update(document, selector, safemode);
}
/// <summary>
/// Updates the specified doc.
/// </summary>
/// <param name = "document">The document.</param>
/// <param name = "selector">The selector.</param>
/// <param name = "flags">The flags.</param>
public void Update(Document document, Document selector, UpdateFlags flags)
{
_collection.Update(document, selector, flags);
}
/// <summary>
/// Updates the specified doc.
/// </summary>
/// <param name = "document">The document.</param>
/// <param name = "selector">The selector.</param>
/// <param name = "flags">The flags.</param>
/// <param name = "safemode">if set to <c>true</c> [safemode].</param>
public void Update(Document document, Document selector, UpdateFlags flags, bool safemode)
{
_collection.Update(document, selector, flags, safemode);
}
/// <summary>
/// Updates all.
/// </summary>
/// <param name = "document">The document.</param>
/// <param name = "selector">The selector.</param>
public void UpdateAll(Document document, Document selector)
{
_collection.UpdateAll(document, selector);
}
/// <summary>
/// Updates all.
/// </summary>
/// <param name = "document">The document.</param>
/// <param name = "selector">The selector.</param>
/// <param name = "safemode">if set to <c>true</c> [safemode].</param>
public void UpdateAll(Document document, Document selector, bool safemode)
{
_collection.UpdateAll(document, selector, safemode);
}
/// <summary>
/// Saves the specified doc.
/// </summary>
/// <param name = "document">The document.</param>
public void Save(Document document)
{
_collection.Save(document);
}
/// <summary>
/// Saves the specified doc.
/// </summary>
/// <param name = "document">The document.</param>
/// <param name = "safemode">if set to <c>true</c> [safemode].</param>
public void Save(Document document, bool safemode)
{
_collection.Save(document, safemode);
}
}
}