Skip to content

Commit 0b6f3ab

Browse files
author
rstam
committed
CSHARP-962: Add SetBits to IndexOptionsBuilder.
1 parent 1eca0fa commit 0b6f3ab

File tree

3 files changed

+58
-0
lines changed

3 files changed

+58
-0
lines changed

MongoDB.Driver/Builders/IndexOptionsBuilder.cs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,16 @@ public static IndexOptionsBuilder SetBackground(bool value)
4848
return new IndexOptionsBuilder().SetBackground(value);
4949
}
5050

51+
/// <summary>
52+
/// Sets the location precision bits.
53+
/// </summary>
54+
/// <param name="value">The value.</param>
55+
/// <returns>The builder (so method calls can be chained).</returns>
56+
public static IndexOptionsBuilder SetBits(int value)
57+
{
58+
return new IndexOptionsBuilder().SetBits(value);
59+
}
60+
5161
/// <summary>
5262
/// Sets the bucket size for geospatial haystack indexes.
5363
/// </summary>
@@ -183,6 +193,17 @@ public IndexOptionsBuilder SetBackground(bool value)
183193
return this;
184194
}
185195

196+
/// <summary>
197+
/// Sets the location precision bits.
198+
/// </summary>
199+
/// <param name="value">The value.</param>
200+
/// <returns>The builder (so method calls can be chained).</returns>
201+
public IndexOptionsBuilder SetBits(int value)
202+
{
203+
_document["bits"] = value;
204+
return this;
205+
}
206+
186207
/// <summary>
187208
/// Sets the bucket size for geospatial haystack indexes.
188209
/// </summary>
@@ -352,6 +373,16 @@ public static IndexOptionsBuilder<TDocument> SetBackground(bool value)
352373
return new IndexOptionsBuilder<TDocument>().SetBackground(value);
353374
}
354375

376+
/// <summary>
377+
/// Sets the location precision bits.
378+
/// </summary>
379+
/// <param name="value">The value.</param>
380+
/// <returns>The builder (so method calls can be chained).</returns>
381+
public static IndexOptionsBuilder<TDocument> SetBits(int value)
382+
{
383+
return new IndexOptionsBuilder<TDocument>().SetBits(value);
384+
}
385+
355386
/// <summary>
356387
/// Sets the bucket size for geospatial haystack indexes.
357388
/// </summary>
@@ -493,6 +524,17 @@ public IndexOptionsBuilder<TDocument> SetBackground(bool value)
493524
return this;
494525
}
495526

527+
/// <summary>
528+
/// Sets the location precision bits.
529+
/// </summary>
530+
/// <param name="value">The value.</param>
531+
/// <returns>The builder (so method calls can be chained).</returns>
532+
public IndexOptionsBuilder<TDocument> SetBits(int value)
533+
{
534+
_indexOptionsBuilder.SetBits(value);
535+
return this;
536+
}
537+
496538
/// <summary>
497539
/// Sets the bucket size for geospatial haystack indexes.
498540
/// </summary>

MongoDB.DriverUnitTests/Builders/IndexOptionsBuilderTests.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,14 @@ public void TestBackground()
3131
Assert.AreEqual(expected, options.ToJson());
3232
}
3333

34+
[Test]
35+
public void TestBits()
36+
{
37+
var options = IndexOptions.SetBits(32);
38+
string expected = "{ \"bits\" : 32 }";
39+
Assert.AreEqual(expected, options.ToJson());
40+
}
41+
3442
[Test]
3543
public void TestDropDups()
3644
{

MongoDB.DriverUnitTests/Builders/IndexOptionsBuilderTypedTests.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,14 @@ public void TestBackground()
3939
Assert.AreEqual(expected, options.ToJson());
4040
}
4141

42+
[Test]
43+
public void TestBits()
44+
{
45+
var options = IndexOptions<TestClass>.SetBits(32);
46+
string expected = "{ \"bits\" : 32 }";
47+
Assert.AreEqual(expected, options.ToJson());
48+
}
49+
4250
[Test]
4351
public void TestDropDups()
4452
{

0 commit comments

Comments
 (0)