Skip to content

Commit 75ee36d

Browse files
CSHARP-2738: Deprecate mapparams, out.sharded, and out.nonAtomic arguments to mapReduce.
1 parent 7a2af91 commit 75ee36d

File tree

13 files changed

+154
-36
lines changed

13 files changed

+154
-36
lines changed

src/MongoDB.Driver.Core/Core/Operations/MapReduceOperationBase.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@
1414
*/
1515

1616
using System;
17-
using System.Collections.Generic;
18-
using System.Threading;
19-
using System.Threading.Tasks;
2017
using MongoDB.Bson;
2118
using MongoDB.Driver.Core.Bindings;
2219
using MongoDB.Driver.Core.Connections;
@@ -120,6 +117,7 @@ public BsonJavaScript FinalizeFunction
120117
/// </remarks>
121118
/// <c>true</c> if objects emitted by the map function remain as JavaScript objects; otherwise, <c>false</c>.
122119
/// </value>
120+
[Obsolete("JavaScriptMode is ignored by server versions 4.4.0 and newer.")]
123121
public bool? JavaScriptMode
124122
{
125123
get { return _javaScriptMode; }

src/MongoDB.Driver.Core/Core/Operations/MapReduceOutputToCollectionOperation.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ public bool? BypassDocumentValidation
8282
/// <value>
8383
/// <c>true</c> if the server should not lock the database for merge and reduce output modes; otherwise, <c>false</c>.
8484
/// </value>
85+
[Obsolete("NonAtomicOutput is rejected by server versions 4.4.0 and newer.")]
8586
public bool? NonAtomicOutput
8687
{
8788
get { return _nonAtomicOutput; }
@@ -117,6 +118,7 @@ public MapReduceOutputMode OutputMode
117118
/// <value>
118119
/// <c>true</c> if the output collection should be sharded; otherwise, <c>false</c>.
119120
/// </value>
121+
[Obsolete("ShardedOutput is rejected by server versions 4.4.0 and newer.")]
120122
public bool? ShardedOutput
121123
{
122124
get { return _shardedOutput; }

src/MongoDB.Driver.Legacy/CommandResults/MapReduceResult.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ public string DatabaseName
8484
/// <summary>
8585
/// Gets the duration.
8686
/// </summary>
87+
[Obsolete("Duration is not available on server versions 4.4.0 and newer.")]
8788
public TimeSpan Duration
8889
{
8990
get { return TimeSpan.FromMilliseconds(Response["timeMillis"].ToInt32()); }
@@ -92,6 +93,7 @@ public TimeSpan Duration
9293
/// <summary>
9394
/// Gets the emit count.
9495
/// </summary>
96+
[Obsolete("EmitCount is not available on server versions 4.4.0 and newer.")]
9597
public long EmitCount
9698
{
9799
get { return Response["counts"]["emit"].ToInt64(); }
@@ -100,6 +102,7 @@ public long EmitCount
100102
/// <summary>
101103
/// Gets the output count.
102104
/// </summary>
105+
[Obsolete("OutputCount is not available on server versions 4.4.0 and newer.")]
103106
public long OutputCount
104107
{
105108
get { return Response["counts"]["output"].ToInt64(); }
@@ -116,6 +119,7 @@ public IEnumerable<BsonDocument> InlineResults
116119
/// <summary>
117120
/// Gets the input count.
118121
/// </summary>
122+
[Obsolete("InputCount is not available on server versions 4.4.0 and newer.")]
119123
public long InputCount
120124
{
121125
get { return Response["counts"]["input"].ToInt64(); }

src/MongoDB.Driver.Legacy/MapReduceArgs.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ public BsonJavaScript FinalizeFunction
122122
/// <summary>
123123
/// Gets or sets the JavaScript mode (if true all intermediate values are kept in memory as JavaScript objects).
124124
/// </summary>
125+
[Obsolete("JsMode is ignored by server versions 4.4.0 and newer.")]
125126
public bool? JsMode
126127
{
127128
get { return _jsMode; }
@@ -176,6 +177,7 @@ public string OutputDatabaseName
176177
/// <summary>
177178
/// Gets or sets a value indicating whether Merge and Reduce output should not be atomic.
178179
/// </summary>
180+
[Obsolete("OutputIsNonAtomic is rejected by server versions 4.4.0 and newer.")]
179181
public bool? OutputIsNonAtomic
180182
{
181183
get { return _outputIsNonAtomic; }
@@ -185,6 +187,7 @@ public bool? OutputIsNonAtomic
185187
/// <summary>
186188
/// Gets or sets a value indicating whether the output is sharded.
187189
/// </summary>
190+
[Obsolete("OutputIsSharded is rejected by server versions 4.4.0 and newer.")]
188191
public bool? OutputIsSharded
189192
{
190193
get { return _outputIsSharded; }

src/MongoDB.Driver.Legacy/MongoCollection.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1686,7 +1686,9 @@ private MapReduceResult MapReduce(IClientSessionHandle session, MapReduceArgs ar
16861686
Collation = args.Collation,
16871687
Filter = query,
16881688
FinalizeFunction = args.FinalizeFunction,
1689+
#pragma warning disable 618
16891690
JavaScriptMode = args.JsMode,
1691+
#pragma warning restore 618
16901692
Limit = args.Limit,
16911693
MaxTime = args.MaxTime,
16921694
ReadConcern = _settings.ReadConcern,
@@ -1714,13 +1716,19 @@ private MapReduceResult MapReduce(IClientSessionHandle session, MapReduceArgs ar
17141716
Collation = args.Collation,
17151717
Filter = query,
17161718
FinalizeFunction = args.FinalizeFunction,
1719+
#pragma warning disable 618
17171720
JavaScriptMode = args.JsMode,
1721+
#pragma warning restore 618
17181722
Limit = args.Limit,
17191723
MaxTime = args.MaxTime,
1724+
#pragma warning disable 618
17201725
NonAtomicOutput = args.OutputIsNonAtomic,
1726+
#pragma warning restore 618
17211727
OutputMode = outputMode,
17221728
Scope = scope,
1729+
#pragma warning disable 618
17231730
ShardedOutput = args.OutputIsSharded,
1731+
#pragma warning restore 618
17241732
Sort = sort,
17251733
Verbose = args.Verbose,
17261734
WriteConcern = _settings.WriteConcern

src/MongoDB.Driver/MapReduceOptions.cs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ public BsonJavaScript Finalize
8181
/// <summary>
8282
/// Gets or sets the java script mode.
8383
/// </summary>
84+
[Obsolete("JavaScriptMode is ignored by server versions 4.4.0 and newer.")]
8485
public bool? JavaScriptMode
8586
{
8687
get { return _javaScriptMode; }
@@ -177,12 +178,25 @@ public static MapReduceOutputOptions Inline
177178
/// <param name="sharded">Whether the output collection should be sharded.</param>
178179
/// <param name="nonAtomic">Whether the server should not lock the database for the duration of the merge.</param>
179180
/// <returns>A merge map-reduce output options.</returns>
181+
[Obsolete("Use an overload of Merge that does not have sharded and nonAtomic parameters instead.")]
180182
public static MapReduceOutputOptions Merge(string collectionName, string databaseName = null, bool? sharded = null, bool? nonAtomic = null)
181183
{
182184
Ensure.IsNotNull(collectionName, nameof(collectionName));
183185
return new CollectionOutput(collectionName, Core.Operations.MapReduceOutputMode.Merge, databaseName, sharded, nonAtomic);
184186
}
185187

188+
/// <summary>
189+
/// A merge map-reduce output options.
190+
/// </summary>
191+
/// <param name="collectionName">The name of the collection.</param>
192+
/// <param name="databaseName">The name of the database.</param>
193+
/// <returns>A merge map-reduce output options.</returns>
194+
public static MapReduceOutputOptions Merge(string collectionName, string databaseName)
195+
{
196+
Ensure.IsNotNull(collectionName, nameof(collectionName));
197+
return new CollectionOutput(collectionName, Core.Operations.MapReduceOutputMode.Merge, databaseName);
198+
}
199+
186200
/// <summary>
187201
/// A reduce map-reduce output options.
188202
/// </summary>
@@ -191,25 +205,51 @@ public static MapReduceOutputOptions Merge(string collectionName, string databas
191205
/// <param name="sharded">Whether the output collection should be sharded.</param>
192206
/// <param name="nonAtomic">Whether the server should not lock the database for the duration of the reduce.</param>
193207
/// <returns>A reduce map-reduce output options.</returns>
208+
[Obsolete("Use an overload of Reduce that does not have sharded and nonAtomic parameters instead.")]
194209
public static MapReduceOutputOptions Reduce(string collectionName, string databaseName = null, bool? sharded = null, bool? nonAtomic = null)
195210
{
196211
Ensure.IsNotNull(collectionName, nameof(collectionName));
197212
return new CollectionOutput(collectionName, Core.Operations.MapReduceOutputMode.Reduce, databaseName, sharded, nonAtomic);
198213
}
199214

215+
/// <summary>
216+
/// A reduce map-reduce output options.
217+
/// </summary>
218+
/// <param name="collectionName">The name of the collection.</param>
219+
/// <param name="databaseName">The name of the database.</param>
220+
/// <returns>A reduce map-reduce output options.</returns>
221+
public static MapReduceOutputOptions Reduce(string collectionName, string databaseName)
222+
{
223+
Ensure.IsNotNull(collectionName, nameof(collectionName));
224+
return new CollectionOutput(collectionName, Core.Operations.MapReduceOutputMode.Reduce, databaseName);
225+
}
226+
200227
/// <summary>
201228
/// A replace map-reduce output options.
202229
/// </summary>
203230
/// <param name="collectionName">The name of the collection.</param>
204231
/// <param name="databaseName">Name of the database.</param>
205232
/// <param name="sharded">Whether the output collection should be sharded.</param>
206233
/// <returns>A replace map-reduce output options.</returns>
234+
[Obsolete("Use an overload of Replace that does not have a sharded parameter instead.")]
207235
public static MapReduceOutputOptions Replace(string collectionName, string databaseName = null, bool? sharded = null)
208236
{
209237
Ensure.IsNotNull(collectionName, nameof(collectionName));
210238
return new CollectionOutput(collectionName, Core.Operations.MapReduceOutputMode.Replace, databaseName, sharded, null);
211239
}
212240

241+
/// <summary>
242+
/// A replace map-reduce output options.
243+
/// </summary>
244+
/// <param name="collectionName">The name of the collection.</param>
245+
/// <param name="databaseName">Name of the database.</param>
246+
/// <returns>A replace map-reduce output options.</returns>
247+
public static MapReduceOutputOptions Replace(string collectionName, string databaseName)
248+
{
249+
Ensure.IsNotNull(collectionName, nameof(collectionName));
250+
return new CollectionOutput(collectionName, Core.Operations.MapReduceOutputMode.Replace, databaseName);
251+
}
252+
213253
internal sealed class InlineOutput : MapReduceOutputOptions
214254
{
215255
internal InlineOutput()
@@ -243,6 +283,7 @@ public string DatabaseName
243283
get { return _databaseName; }
244284
}
245285

286+
[Obsolete("NonAtomic is rejected by server versions 4.4.0 and newer.")]
246287
public bool? NonAtomic
247288
{
248289
get { return _nonAtomic; }
@@ -253,6 +294,7 @@ public Core.Operations.MapReduceOutputMode OutputMode
253294
get { return _outputMode; }
254295
}
255296

297+
[Obsolete("Sharded is rejected by server versions 4.4.0 and newer.")]
256298
public bool? Sharded
257299
{
258300
get { return _sharded; }

src/MongoDB.Driver/MongoCollectionImpl.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1010,7 +1010,9 @@ private MapReduceOperation<TResult> CreateMapReduceOperation<TResult>(BsonJavaSc
10101010
Collation = options.Collation,
10111011
Filter = options.Filter == null ? null : options.Filter.Render(_documentSerializer, _settings.SerializerRegistry),
10121012
FinalizeFunction = options.Finalize,
1013+
#pragma warning disable 618
10131014
JavaScriptMode = options.JavaScriptMode,
1015+
#pragma warning restore 618
10141016
Limit = options.Limit,
10151017
MaxTime = options.MaxTime,
10161018
ReadConcern = _settings.ReadConcern,
@@ -1039,13 +1041,19 @@ private MapReduceOutputToCollectionOperation CreateMapReduceOutputToCollectionOp
10391041
Collation = options.Collation,
10401042
Filter = options.Filter == null ? null : options.Filter.Render(_documentSerializer, _settings.SerializerRegistry),
10411043
FinalizeFunction = options.Finalize,
1044+
#pragma warning disable 618
10421045
JavaScriptMode = options.JavaScriptMode,
1046+
#pragma warning restore 618
10431047
Limit = options.Limit,
10441048
MaxTime = options.MaxTime,
1049+
#pragma warning disable 618
10451050
NonAtomicOutput = collectionOutputOptions.NonAtomic,
1051+
#pragma warning restore 618
10461052
Scope = options.Scope,
10471053
OutputMode = collectionOutputOptions.OutputMode,
1054+
#pragma warning disable 618
10481055
ShardedOutput = collectionOutputOptions.Sharded,
1056+
#pragma warning restore 618
10491057
Sort = options.Sort == null ? null : options.Sort.Render(_documentSerializer, _settings.SerializerRegistry),
10501058
Verbose = options.Verbose,
10511059
WriteConcern = _settings.WriteConcern

tests/MongoDB.Driver.Core.Tests/Core/Operations/MapReduceLegacyOperationTests.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
using System;
1717
using System.Collections.Generic;
1818
using System.Reflection;
19-
using System.Threading;
20-
using System.Threading.Tasks;
2119
using FluentAssertions;
2220
using MongoDB.Bson;
2321
using MongoDB.Bson.Serialization;
@@ -81,8 +79,9 @@ public void Execute_should_return_expected_results(
8179
};
8280

8381
var result = ExecuteOperation(subject, async);
82+
var results = result["results"].AsBsonArray.ToList();
8483

85-
result["results"].Should().Be(new BsonArray(expectedResults));
84+
results.Should().BeEquivalentTo(new BsonArray(expectedResults));
8685
}
8786

8887
[SkippableTheory]

tests/MongoDB.Driver.Core.Tests/Core/Operations/MapReduceOperationBaseTests.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,9 @@ public void constructor_should_initialize_instance()
7272
subject.Collation.Should().BeNull();
7373
subject.Filter.Should().BeNull();
7474
subject.FinalizeFunction.Should().BeNull();
75+
#pragma warning disable 618
7576
subject.JavaScriptMode.Should().NotHaveValue();
77+
#pragma warning restore 618
7678
subject.Limit.Should().NotHaveValue();
7779
subject.MaxTime.Should().NotHaveValue();
7880
subject.Scope.Should().BeNull();
@@ -240,7 +242,9 @@ public void CreateCommand_should_return_the_expected_result_when_JavaScriptMode_
240242
{
241243
var subject = new FakeMapReduceOperation(_collectionNamespace, _mapFunction, _reduceFunction, _messageEncoderSettings)
242244
{
245+
#pragma warning disable 618
243246
JavaScriptMode = javaScriptMode
247+
#pragma warning restore 618
244248
};
245249
var session = OperationTestHelper.CreateSession();
246250
var connectionDescription = OperationTestHelper.CreateConnectionDescription();
@@ -432,8 +436,10 @@ public void JavaScriptMode_should_get_and_set_value(
432436
{
433437
var subject = new FakeMapReduceOperation(_collectionNamespace, _mapFunction, _reduceFunction, _messageEncoderSettings);
434438

439+
#pragma warning disable 618
435440
subject.JavaScriptMode = value;
436441
var result = subject.JavaScriptMode;
442+
#pragma warning restore 618
437443

438444
result.Should().Be(value);
439445
}

0 commit comments

Comments
 (0)