FindOneAndUpdateOptions.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /* Copyright 2010-present MongoDB Inc.
  2. *
  3. * Licensed under the Apache License, Version 2.0 (the "License");
  4. * you may not use this file except in compliance with the License.
  5. * You may obtain a copy of the License at
  6. *
  7. * http://www.apache.org/licenses/LICENSE-2.0
  8. *
  9. * Unless required by applicable law or agreed to in writing, software
  10. * distributed under the License is distributed on an "AS IS" BASIS,
  11. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. * See the License for the specific language governing permissions and
  13. * limitations under the License.
  14. */
  15. using System;
  16. using System.Collections.Generic;
  17. using System.Linq;
  18. using MongoDB.Driver.Core.Misc;
  19. namespace MongoDB.Driver
  20. {
  21. /// <summary>
  22. /// Options for a findAndModify command to update an object.
  23. /// </summary>
  24. /// <typeparam name="TDocument">The type of the document.</typeparam>
  25. /// <typeparam name="TProjection">The type of the projection (same as TDocument if there is no projection).</typeparam>
  26. public class FindOneAndUpdateOptions<TDocument, TProjection>
  27. {
  28. // fields
  29. private IEnumerable<ArrayFilterDefinition> _arrayFilters;
  30. private bool? _bypassDocumentValidation;
  31. private Collation _collation;
  32. private bool _isUpsert;
  33. private TimeSpan? _maxTime;
  34. private ProjectionDefinition<TDocument, TProjection> _projection;
  35. private ReturnDocument _returnDocument;
  36. private SortDefinition<TDocument> _sort;
  37. // constructors
  38. /// <summary>
  39. /// Initializes a new instance of the <see cref="FindOneAndUpdateOptions{TDocument, TProjection}"/> class.
  40. /// </summary>
  41. public FindOneAndUpdateOptions()
  42. {
  43. _returnDocument = ReturnDocument.Before;
  44. }
  45. // properties
  46. /// <summary>
  47. /// Gets or sets the array filters.
  48. /// </summary>
  49. /// <value>
  50. /// The array filters.
  51. /// </value>
  52. public IEnumerable<ArrayFilterDefinition> ArrayFilters
  53. {
  54. get { return _arrayFilters; }
  55. set { _arrayFilters = value; }
  56. }
  57. /// <summary>
  58. /// Gets or sets a value indicating whether to bypass document validation.
  59. /// </summary>
  60. public bool? BypassDocumentValidation
  61. {
  62. get { return _bypassDocumentValidation; }
  63. set { _bypassDocumentValidation = value; }
  64. }
  65. /// <summary>
  66. /// Gets or sets the collation.
  67. /// </summary>
  68. public Collation Collation
  69. {
  70. get { return _collation; }
  71. set { _collation = value; }
  72. }
  73. /// <summary>
  74. /// Gets or sets a value indicating whether to insert the document if it doesn't already exist.
  75. /// </summary>
  76. public bool IsUpsert
  77. {
  78. get { return _isUpsert; }
  79. set { _isUpsert = value; }
  80. }
  81. /// <summary>
  82. /// Gets or sets the maximum time.
  83. /// </summary>
  84. public TimeSpan? MaxTime
  85. {
  86. get { return _maxTime; }
  87. set { _maxTime = Ensure.IsNullOrInfiniteOrGreaterThanOrEqualToZero(value, nameof(value)); }
  88. }
  89. /// <summary>
  90. /// Gets or sets the projection.
  91. /// </summary>
  92. public ProjectionDefinition<TDocument, TProjection> Projection
  93. {
  94. get { return _projection; }
  95. set { _projection = value; }
  96. }
  97. /// <summary>
  98. /// Gets or sets which version of the document to return.
  99. /// </summary>
  100. public ReturnDocument ReturnDocument
  101. {
  102. get { return _returnDocument; }
  103. set { _returnDocument = value; }
  104. }
  105. /// <summary>
  106. /// Gets or sets the sort.
  107. /// </summary>
  108. public SortDefinition<TDocument> Sort
  109. {
  110. get { return _sort; }
  111. set { _sort = value; }
  112. }
  113. }
  114. /// <summary>
  115. /// Options for a findAndModify command to update an object.
  116. /// </summary>
  117. /// <typeparam name="TDocument">The type of the document and the result.</typeparam>
  118. public class FindOneAndUpdateOptions<TDocument> : FindOneAndUpdateOptions<TDocument, TDocument>
  119. {
  120. }
  121. }