Skip to content

Commit 3ea5362

Browse files
author
rstam
committed
CSHARP-551: Add SystemFlags and UserFlags to CollectionStatsResult (and obsolete Flags).
1 parent b75ebec commit 3ea5362

File tree

2 files changed

+96
-2
lines changed

2 files changed

+96
-2
lines changed

Driver/Core/CommandResults/CollectionStatsResult.cs

Lines changed: 86 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,38 @@
2323

2424
namespace MongoDB.Driver
2525
{
26+
/// <summary>
27+
/// Represents collection system flags.
28+
/// </summary>
29+
[Flags]
30+
public enum CollectionSystemFlags
31+
{
32+
/// <summary>
33+
/// No flags.
34+
/// </summary>
35+
None = 0,
36+
/// <summary>
37+
/// The collection has an _id index.
38+
/// </summary>
39+
HaveIdIndex = 1
40+
}
41+
42+
/// <summary>
43+
/// Represents collection user flags.
44+
/// </summary>
45+
[Flags]
46+
public enum CollectionUserFlags
47+
{
48+
/// <summary>
49+
/// No flags.
50+
/// </summary>
51+
None = 0,
52+
/// <summary>
53+
/// User power of 2 size.
54+
/// </summary>
55+
UsePowerOf2Size = 1
56+
}
57+
2658
/// <summary>
2759
/// Represents the results of the collection stats command.
2860
/// </summary>
@@ -68,9 +100,22 @@ public int ExtentCount
68100
/// <summary>
69101
/// Gets the flags.
70102
/// </summary>
103+
[Obsolete("Use SystemFlags or UserFlags instead.")]
71104
public int Flags
72105
{
73-
get { return Response["flags"].AsInt32; }
106+
get
107+
{
108+
// flags was renamed to systemFlags in server version 2.2
109+
BsonValue flags;
110+
if (Response.TryGetValue("flags", out flags) || Response.TryGetValue("systemFlags", out flags))
111+
{
112+
return flags.AsInt32;
113+
}
114+
else
115+
{
116+
return 0;
117+
}
118+
}
74119
}
75120

76121
/// <summary>
@@ -153,6 +198,26 @@ public long StorageSize
153198
get { return Response["storageSize"].ToInt64(); }
154199
}
155200

201+
/// <summary>
202+
/// Gets the system flags.
203+
/// </summary>
204+
public CollectionSystemFlags SystemFlags
205+
{
206+
get
207+
{
208+
// systemFlags was called flags prior to server version 2.2
209+
BsonValue systemFlags;
210+
if (Response.TryGetValue("systemFlags", out systemFlags) || Response.TryGetValue("flags", out systemFlags))
211+
{
212+
return (CollectionSystemFlags)systemFlags.AsInt32;
213+
}
214+
else
215+
{
216+
return CollectionSystemFlags.None;
217+
}
218+
}
219+
}
220+
156221
/// <summary>
157222
/// Gets the total index size.
158223
/// </summary>
@@ -161,6 +226,26 @@ public long TotalIndexSize
161226
get { return Response["totalIndexSize"].ToInt64(); }
162227
}
163228

229+
/// <summary>
230+
/// Gets the user flags.
231+
/// </summary>
232+
public CollectionUserFlags UserFlags
233+
{
234+
get
235+
{
236+
// userFlags was first introduced in server version 2.2
237+
BsonValue userFlags;
238+
if (Response.TryGetValue("userFlags", out userFlags))
239+
{
240+
return (CollectionUserFlags)userFlags.AsInt32;
241+
}
242+
else
243+
{
244+
return CollectionUserFlags.None;
245+
}
246+
}
247+
}
248+
164249
// nested classes
165250
/// <summary>
166251
/// Represents a collection of index sizes.

DriverUnitTests/Core/CommandResults/CollectionStatsResultTests.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public void Setup()
4444
public void Test()
4545
{
4646
// make sure collection exists and has exactly one document
47-
_collection.RemoveAll();
47+
_collection.Drop();
4848
_collection.Insert(new BsonDocument());
4949

5050
var result = _collection.GetStats();
@@ -54,17 +54,26 @@ public void Test()
5454
Assert.IsTrue(result.AverageObjectSize > 0.0);
5555
Assert.IsTrue(result.DataSize > 0);
5656
Assert.IsTrue(result.ExtentCount > 0);
57+
#pragma warning disable 618
58+
Assert.AreEqual(1, result.Flags);
59+
#pragma warning restore
5760
Assert.IsTrue(result.IndexCount > 0);
5861
Assert.IsTrue(result.IndexSizes["_id_"] > 0);
5962
Assert.IsTrue(result.IndexSizes.ContainsKey("_id_"));
6063
Assert.IsTrue(result.IndexSizes.Count > 0);
6164
Assert.IsTrue(result.IndexSizes.Keys.Contains("_id_"));
6265
Assert.IsTrue(result.IndexSizes.Values.Count() > 0);
6366
Assert.IsTrue(result.IndexSizes.Values.First() > 0);
67+
Assert.IsFalse(result.IsCapped);
6468
Assert.IsTrue(result.LastExtentSize > 0);
69+
Assert.IsFalse(result.Response.Contains("max"));
70+
Assert.AreEqual(_collection.FullName, result.Namespace);
71+
Assert.AreEqual(1, result.ObjectCount);
6572
Assert.IsTrue(result.PaddingFactor > 0.0);
6673
Assert.IsTrue(result.StorageSize > 0);
74+
Assert.AreEqual(CollectionSystemFlags.HaveIdIndex, result.SystemFlags);
6775
Assert.IsTrue(result.TotalIndexSize > 0);
76+
Assert.AreEqual(CollectionUserFlags.None, result.UserFlags);
6877
}
6978
}
7079
}

0 commit comments

Comments
 (0)