-
Notifications
You must be signed in to change notification settings - Fork 1.3k
CSHARP-4706: Support for $out to Time-series collections #1223
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 7 commits
030b6cb
ddab8bb
0f2978e
44a3fc4
6edcc4b
696c827
1776038
659e1c9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -330,7 +330,7 @@ private IReadOnlyList<BsonDocument> SimplifyOutStageIfOutputDatabaseIsSameAsInpu | |
{ | ||
var lastStage = pipeline.Last(); | ||
var lastStageName = lastStage.GetElement(0).Name; | ||
if (lastStageName == "$out" && lastStage["$out"] is BsonDocument outDocument) | ||
if (lastStageName == "$out" && lastStage["$out"] is BsonDocument outDocument && !outDocument.Contains("timeseries")) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we have this tested directly or indirectly somewhere? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is tested indirectly through the |
||
{ | ||
if (outDocument.TryGetValue("db", out var db) && db.IsString && | ||
outDocument.TryGetValue("coll", out var coll) && coll.IsString) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -970,6 +970,25 @@ public static PipelineDefinition<TInput, TOutput> Out<TInput, TOutput>( | |
return pipeline.AppendStage(PipelineStageDefinitionBuilder.Out<TOutput>(outputCollection)); | ||
} | ||
|
||
/// <summary> | ||
/// Appends a $out stage to the pipeline. | ||
/// </summary> | ||
/// <typeparam name="TInput">The type of the input documents.</typeparam> | ||
/// <typeparam name="TOutput">The type of the output documents.</typeparam> | ||
/// <param name="pipeline">The pipeline.</param> | ||
/// <param name="outputCollection">The output collection.</param> | ||
/// <param name="timeSeriesOptions">The time-series options</param> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. time-series => time series And add period at end of the param description. |
||
/// <returns>A new pipeline with an additional stage.</returns> | ||
/// <exception cref="System.NotSupportedException"></exception> | ||
public static PipelineDefinition<TInput, TOutput> Out<TInput, TOutput>( | ||
this PipelineDefinition<TInput, TOutput> pipeline, | ||
IMongoCollection<TOutput> outputCollection, | ||
TimeSeriesOptions timeSeriesOptions) | ||
{ | ||
Ensure.IsNotNull(pipeline, nameof(pipeline)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should either merge overloads (add There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Optional parameters are problematic and I think we should avoid them in our public API. We can use them internally where it makes sense, but not in our public API. Reason 1: The optional value is inserted into the calling code at compile-time for the calling code. So if you change your default value, but don't recompile the calling code, you'll still use the same value. Reason 2: Even more insidious is that the C# compiler doesn't enforce consistency among default values. The following is perfectly valid:
The output is:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see that we are already doing this elsewhere in our Fluent Aggregate API. Sigh. I guess we can use |
||
return pipeline.AppendStage(PipelineStageDefinitionBuilder.Out<TOutput>(outputCollection, timeSeriesOptions)); | ||
} | ||
|
||
/// <summary> | ||
/// Appends a $project stage to the pipeline. | ||
/// </summary> | ||
|
@@ -1111,7 +1130,7 @@ public static PipelineDefinition<TInput, TOutput> ReplaceWith<TInput, TIntermedi | |
/// </param> | ||
/// <param name="scoreDetails"> | ||
/// Flag that specifies whether to return a detailed breakdown | ||
/// of the score for each document in the result. | ||
/// of the score for each document in the result. | ||
/// </param> | ||
/// <returns>A new pipeline with an additional stage.</returns> | ||
public static PipelineDefinition<TInput, TOutput> Search<TInput, TOutput>( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1244,17 +1244,36 @@ public static PipelineStageDefinition<TInput, TOutput> OfType<TInput, TOutput>( | |
/// </summary> | ||
/// <typeparam name="TInput">The type of the input documents.</typeparam> | ||
/// <param name="outputCollection">The output collection.</param> | ||
/// <param name="timeSeriesOptions">The time series options</param> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Period at end of sentence. |
||
/// <returns>The stage.</returns> | ||
public static PipelineStageDefinition<TInput, TInput> Out<TInput>( | ||
IMongoCollection<TInput> outputCollection) | ||
IMongoCollection<TInput> outputCollection, | ||
TimeSeriesOptions timeSeriesOptions) | ||
{ | ||
Ensure.IsNotNull(outputCollection, nameof(outputCollection)); | ||
var outputDatabaseName = outputCollection.Database.DatabaseNamespace.DatabaseName; | ||
var outputCollectionName = outputCollection.CollectionNamespace.CollectionName; | ||
var outDocument = new BsonDocument { { "db", outputDatabaseName }, { "coll", outputCollectionName } }; | ||
var outDocument = new BsonDocument | ||
{ | ||
{ "db", outputDatabaseName }, | ||
{ "coll", outputCollectionName }, | ||
{ "timeseries", () => timeSeriesOptions.ToBsonDocument(), timeSeriesOptions != null} | ||
}; | ||
return new BsonDocumentPipelineStageDefinition<TInput, TInput>(new BsonDocument("$out", outDocument)); | ||
} | ||
|
||
/// <summary> | ||
/// Creates a $out stage. | ||
/// </summary> | ||
/// <typeparam name="TInput">The type of the input documents.</typeparam> | ||
/// <param name="outputCollection">The output collection.</param> | ||
/// <returns>The stage.</returns> | ||
public static PipelineStageDefinition<TInput, TInput> Out<TInput>( | ||
adelinowona marked this conversation as resolved.
Show resolved
Hide resolved
|
||
IMongoCollection<TInput> outputCollection) | ||
{ | ||
return Out(outputCollection, null); | ||
} | ||
|
||
/// <summary> | ||
/// Creates a $project stage. | ||
/// </summary> | ||
|
@@ -1331,7 +1350,7 @@ public static PipelineStageDefinition<TInput, TOutput> Project<TInput, TOutput>( | |
/// </param> | ||
/// <param name="scoreDetails"> | ||
/// Flag that specifies whether to return a detailed breakdown | ||
/// of the score for each document in the result. | ||
/// of the score for each document in the result. | ||
/// </param> | ||
/// <returns>The stage.</returns> | ||
public static PipelineStageDefinition<TInput, TInput> Search<TInput>( | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alphabetical order (field and property).