UpdateManyModel.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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 MongoDB.Driver.Core.Misc;
  16. using System;
  17. using System.Collections.Generic;
  18. namespace MongoDB.Driver
  19. {
  20. /// <summary>
  21. /// Model for updating many documents.
  22. /// </summary>
  23. /// <typeparam name="TDocument">The type of the document.</typeparam>
  24. #if NET452
  25. [Serializable]
  26. #endif
  27. public sealed class UpdateManyModel<TDocument> : WriteModel<TDocument>
  28. {
  29. // fields
  30. private IEnumerable<ArrayFilterDefinition> _arrayFilters;
  31. private Collation _collation;
  32. private readonly FilterDefinition<TDocument> _filter;
  33. private bool _isUpsert;
  34. private readonly UpdateDefinition<TDocument> _update;
  35. // constructors
  36. /// <summary>
  37. /// Initializes a new instance of the <see cref="UpdateManyModel{TDocument}"/> class.
  38. /// </summary>
  39. /// <param name="filter">The filter.</param>
  40. /// <param name="update">The update.</param>
  41. public UpdateManyModel(FilterDefinition<TDocument> filter, UpdateDefinition<TDocument> update)
  42. {
  43. _filter = Ensure.IsNotNull(filter, nameof(filter));
  44. _update = Ensure.IsNotNull(update, nameof(update));
  45. }
  46. // properties
  47. /// <summary>
  48. /// Gets or sets the array filters.
  49. /// </summary>
  50. /// <value>
  51. /// The array filters.
  52. /// </value>
  53. public IEnumerable<ArrayFilterDefinition> ArrayFilters
  54. {
  55. get { return _arrayFilters; }
  56. set { _arrayFilters = value; }
  57. }
  58. /// <summary>
  59. /// Gets or sets the collation.
  60. /// </summary>
  61. public Collation Collation
  62. {
  63. get { return _collation; }
  64. set { _collation = value; }
  65. }
  66. /// <summary>
  67. /// Gets the filter.
  68. /// </summary>
  69. public FilterDefinition<TDocument> Filter
  70. {
  71. get { return _filter; }
  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 the update.
  83. /// </summary>
  84. public UpdateDefinition<TDocument> Update
  85. {
  86. get { return _update; }
  87. }
  88. /// <inheritdoc/>
  89. public override WriteModelType ModelType
  90. {
  91. get { return WriteModelType.UpdateMany; }
  92. }
  93. }
  94. }