Skip to content

Commit b07f674

Browse files
committed
CSHARP-1741: Added support for $bucketAuto.
1 parent 18d204a commit b07f674

16 files changed

+1074
-261
lines changed
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
/* Copyright 2016 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+
16+
using MongoDB.Driver.Core.Misc;
17+
18+
namespace MongoDB.Driver
19+
{
20+
/// <summary>
21+
/// Represents the granularity value for a $bucketAuto stage.
22+
/// </summary>
23+
public struct AggregateBucketAutoGranularity
24+
{
25+
#region static
26+
/// <summary>
27+
/// Gets the E6 granularity.
28+
/// </summary>
29+
public static AggregateBucketAutoGranularity E6 => new AggregateBucketAutoGranularity("E6");
30+
31+
/// <summary>
32+
/// Gets the E12 granularity.
33+
/// </summary>
34+
public static AggregateBucketAutoGranularity E12 => new AggregateBucketAutoGranularity("E12");
35+
36+
/// <summary>
37+
/// Gets the E24 granularity.
38+
/// </summary>
39+
public static AggregateBucketAutoGranularity E24 => new AggregateBucketAutoGranularity("E24");
40+
41+
/// <summary>
42+
/// Gets the E48 granularity.
43+
/// </summary>
44+
public static AggregateBucketAutoGranularity E48 => new AggregateBucketAutoGranularity("E48");
45+
46+
/// <summary>
47+
/// Gets the E96 granularity.
48+
/// </summary>
49+
public static AggregateBucketAutoGranularity E96 => new AggregateBucketAutoGranularity("E96");
50+
51+
/// <summary>
52+
/// Gets the E192 granularity.
53+
/// </summary>
54+
public static AggregateBucketAutoGranularity E192 => new AggregateBucketAutoGranularity("E192");
55+
56+
/// <summary>
57+
/// Gets the POWERSOF2 granularity.
58+
/// </summary>
59+
public static AggregateBucketAutoGranularity PowersOf2 => new AggregateBucketAutoGranularity("POWERSOF2");
60+
61+
/// <summary>
62+
/// Gets the R5 granularity.
63+
/// </summary>
64+
public static AggregateBucketAutoGranularity R5 => new AggregateBucketAutoGranularity("R5");
65+
66+
/// <summary>
67+
/// Gets the R10 granularity.
68+
/// </summary>
69+
public static AggregateBucketAutoGranularity R10 => new AggregateBucketAutoGranularity("R10");
70+
71+
/// <summary>
72+
/// Gets the R20 granularity.
73+
/// </summary>
74+
public static AggregateBucketAutoGranularity R20 => new AggregateBucketAutoGranularity("R20");
75+
76+
/// <summary>
77+
/// Gets the R40 granularity.
78+
/// </summary>
79+
public static AggregateBucketAutoGranularity R40 => new AggregateBucketAutoGranularity("R40");
80+
81+
/// <summary>
82+
/// Gets the R80 granularity.
83+
/// </summary>
84+
public static AggregateBucketAutoGranularity R80 => new AggregateBucketAutoGranularity("R80");
85+
86+
/// <summary>
87+
/// Gets the 1-2-5 granularity.
88+
/// </summary>
89+
public static AggregateBucketAutoGranularity S1_2_5 => new AggregateBucketAutoGranularity("1-2-5");
90+
91+
#endregion
92+
93+
private readonly string _value;
94+
95+
/// <summary>
96+
/// Initializes a new instance of the <see cref="AggregateBucketAutoGranularity"/> struct.
97+
/// </summary>
98+
/// <param name="value">The value.</param>
99+
public AggregateBucketAutoGranularity(string value)
100+
{
101+
_value = Ensure.IsNotNull(value, nameof(value));
102+
}
103+
104+
/// <summary>
105+
/// Gets the value.
106+
/// </summary>
107+
public string Value => _value;
108+
}
109+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/* Copyright 2016 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+
16+
namespace MongoDB.Driver
17+
{
18+
/// <summary>
19+
/// Represents options for the BucketAuto method.
20+
/// </summary>
21+
public class AggregateBucketAutoOptions
22+
{
23+
/// <summary>
24+
/// Gets or sets the granularity.
25+
/// </summary>
26+
public Optional<AggregateBucketAutoGranularity> Granularity { get; set; }
27+
}
28+
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/* Copyright 2016 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+
16+
using MongoDB.Bson.Serialization.Attributes;
17+
18+
namespace MongoDB.Driver
19+
{
20+
/// <summary>
21+
/// Represents the result of the $bucketAuto stage.
22+
/// </summary>
23+
/// <typeparam name="TValue">The type of the value.</typeparam>
24+
public class AggregateBucketAutoResult<TValue>
25+
{
26+
// constructors
27+
/// <summary>
28+
/// Initializes a new instance of the <see cref="AggregateBucketResult{TValue}"/> class.
29+
/// </summary>
30+
/// <param name="id">The inclusive lower boundary of the bucket.</param>
31+
/// <param name="count">The count.</param>
32+
public AggregateBucketAutoResult(AggregateBucketAutoResultId<TValue> id, long count)
33+
{
34+
Id = id;
35+
Count = count;
36+
}
37+
38+
/// <summary>
39+
/// Initializes a new instance of the <see cref="AggregateBucketResult{TValue}" /> class.
40+
/// </summary>
41+
/// <param name="min">The minimum.</param>
42+
/// <param name="max">The maximum.</param>
43+
/// <param name="count">The count.</param>
44+
public AggregateBucketAutoResult(TValue min, TValue max, long count)
45+
{
46+
Id = new AggregateBucketAutoResultId<TValue>(min, max);
47+
Count = count;
48+
}
49+
50+
// public properties
51+
/// <summary>
52+
/// Gets the inclusive lower boundary of the bucket.
53+
/// </summary>
54+
/// <value>
55+
/// The inclusive lower boundary of the bucket.
56+
/// </value>
57+
[BsonId]
58+
public AggregateBucketAutoResultId<TValue> Id { get; private set; }
59+
60+
/// <summary>
61+
/// Gets the count.
62+
/// </summary>
63+
/// <value>
64+
/// The count.
65+
/// </value>
66+
[BsonElement("count")]
67+
public long Count { get; private set; }
68+
69+
/// <summary>
70+
/// Gets the maximum.
71+
/// </summary>
72+
public TValue Max => Id.Max;
73+
74+
/// <summary>
75+
/// Gets the minimum.
76+
/// </summary>
77+
public TValue Min => Id.Min;
78+
}
79+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/* Copyright 2016 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+
16+
using MongoDB.Bson.Serialization.Attributes;
17+
18+
namespace MongoDB.Driver
19+
{
20+
/// <summary>
21+
/// Represents the _id value in the result of a $bucketAuto stage.
22+
/// </summary>
23+
/// <typeparam name="TValue">The type of the values.</typeparam>
24+
public class AggregateBucketAutoResultId<TValue>
25+
{
26+
private readonly TValue _min;
27+
private readonly TValue _max;
28+
29+
/// <summary>
30+
/// Initializes a new instance of the <see cref="AggregateBucketAutoResultId{TValue}"/> class.
31+
/// </summary>
32+
/// <param name="min">The minimum.</param>
33+
/// <param name="max">The maximum.</param>
34+
public AggregateBucketAutoResultId(TValue min, TValue max)
35+
{
36+
_min = min;
37+
_max = max;
38+
}
39+
40+
/// <summary>
41+
/// Gets the max value.
42+
/// </summary>
43+
[BsonElement("max")]
44+
public TValue Max => _max;
45+
46+
/// <summary>
47+
/// Gets the min value.
48+
/// </summary>
49+
[BsonElement("min")]
50+
public TValue Min => _min;
51+
}
52+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/* Copyright 2016 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+
16+
namespace MongoDB.Driver
17+
{
18+
/// <summary>
19+
/// Represents options for the Bucket method.
20+
/// </summary>
21+
public class AggregateBucketOptions<TValue>
22+
{
23+
/// <summary>
24+
/// Gets or sets the default bucket.
25+
/// </summary>
26+
public Optional<TValue> DefaultBucket { get; set; }
27+
}
28+
}

src/MongoDB.Driver/AggregateBucketResult.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,6 @@
1313
* limitations under the License.
1414
*/
1515

16-
using System;
17-
using System.Collections.Generic;
18-
using System.Linq;
19-
using System.Text;
20-
using System.Threading.Tasks;
2116
using MongoDB.Bson.Serialization.Attributes;
2217

2318
namespace MongoDB.Driver

0 commit comments

Comments
 (0)