FindOneAndReplaceOptions.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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 MongoDB.Driver.Core.Misc;
  17. namespace MongoDB.Driver
  18. {
  19. /// <summary>
  20. /// Options for a findAndModify command to replace an object.
  21. /// </summary>
  22. /// <typeparam name="TDocument">The type of the document.</typeparam>
  23. /// <typeparam name="TProjection">The type of the projection (same as TDocument if there is no projection).</typeparam>
  24. public class FindOneAndReplaceOptions<TDocument, TProjection>
  25. {
  26. // fields
  27. private bool? _bypassDocumentValidation;
  28. private Collation _collation;
  29. private bool _isUpsert;
  30. private TimeSpan? _maxTime;
  31. private ProjectionDefinition<TDocument, TProjection> _projection;
  32. private ReturnDocument _returnDocument;
  33. private SortDefinition<TDocument> _sort;
  34. // constructors
  35. /// <summary>
  36. /// Initializes a new instance of the <see cref="FindOneAndReplaceOptions{TDocument, TProjection}"/> class.
  37. /// </summary>
  38. public FindOneAndReplaceOptions()
  39. {
  40. _returnDocument = ReturnDocument.Before;
  41. }
  42. // properties
  43. /// <summary>
  44. /// Gets or sets the collation.
  45. /// </summary>
  46. public Collation Collation
  47. {
  48. get { return _collation; }
  49. set { _collation = value; }
  50. }
  51. /// <summary>
  52. /// Gets or sets a value indicating whether to bypass document validation.
  53. /// </summary>
  54. public bool? BypassDocumentValidation
  55. {
  56. get { return _bypassDocumentValidation; }
  57. set { _bypassDocumentValidation = value; }
  58. }
  59. /// <summary>
  60. /// Gets or sets a value indicating whether to insert the document if it doesn't already exist.
  61. /// </summary>
  62. public bool IsUpsert
  63. {
  64. get { return _isUpsert; }
  65. set { _isUpsert = value; }
  66. }
  67. /// <summary>
  68. /// Gets or sets the maximum time.
  69. /// </summary>
  70. public TimeSpan? MaxTime
  71. {
  72. get { return _maxTime; }
  73. set { _maxTime = Ensure.IsNullOrInfiniteOrGreaterThanOrEqualToZero(value, nameof(value)); }
  74. }
  75. /// <summary>
  76. /// Gets or sets the projection.
  77. /// </summary>
  78. public ProjectionDefinition<TDocument, TProjection> Projection
  79. {
  80. get { return _projection; }
  81. set { _projection = value; }
  82. }
  83. /// <summary>
  84. /// Gets or sets which version of the document to return.
  85. /// </summary>
  86. public ReturnDocument ReturnDocument
  87. {
  88. get { return _returnDocument; }
  89. set { _returnDocument = value; }
  90. }
  91. /// <summary>
  92. /// Gets or sets the sort.
  93. /// </summary>
  94. public SortDefinition<TDocument> Sort
  95. {
  96. get { return _sort; }
  97. set { _sort = value; }
  98. }
  99. }
  100. /// <summary>
  101. /// Options for a findAndModify command to replace an object.
  102. /// </summary>
  103. /// <typeparam name="TDocument">The type of the document and the result.</typeparam>
  104. public class FindOneAndReplaceOptions<TDocument> : FindOneAndReplaceOptions<TDocument, TDocument>
  105. {
  106. }
  107. }