This repository has been archived by the owner on Apr 15, 2019. It is now read-only.
forked from mongodb/mongo-csharp-driver
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented CSHARP-249. GetIndexes now returns GetIndexesResult. Use …
…GetIndexes().RawDocuments if you still want the raw IEnumerable<BsonDocument> result.
- Loading branch information
rstam
committed
Oct 11, 2011
1 parent
4ba580c
commit 1ef39f0
Showing
4 changed files
with
270 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,209 @@ | ||
/* Copyright 2010-2011 10gen Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
using System; | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Text.RegularExpressions; | ||
|
||
using MongoDB.Bson; | ||
using MongoDB.Bson.Serialization; | ||
using MongoDB.Bson.IO; | ||
|
||
namespace MongoDB.Driver { | ||
/// <summary> | ||
/// Represents the result of GetIndexes. | ||
/// </summary> | ||
public class GetIndexesResult : IEnumerable<IndexInfo> { | ||
#region private fields | ||
private BsonDocument[] documents; | ||
private IndexInfo[] indexes; | ||
#endregion | ||
|
||
#region constructors | ||
/// <summary> | ||
/// Initializes a new instance of the GetIndexesResult class. | ||
/// </summary> | ||
public GetIndexesResult( | ||
BsonDocument[] documents | ||
) { | ||
this.documents = documents; | ||
this.indexes = this.documents.Select(d => new IndexInfo(d)).ToArray(); | ||
} | ||
#endregion | ||
|
||
#region public operators | ||
/// <summary> | ||
/// Gets the IndexInfo at the specified index. | ||
/// </summary> | ||
/// <param name="index">The zero-based index of the IndexInfo to get.</param> | ||
/// <returns>An IndexInfo.</returns> | ||
public IndexInfo this[int index] { | ||
get { return indexes[index]; } | ||
} | ||
#endregion | ||
|
||
#region public properties | ||
/// <summary> | ||
/// Gets the count of indexes. | ||
/// </summary> | ||
public int Count { | ||
get { return indexes.Length; } | ||
} | ||
|
||
/// <summary> | ||
/// Gets the raw BSON documents containing the information about the indexes. | ||
/// </summary> | ||
public IEnumerable<BsonDocument> RawDocuments { | ||
get { return documents; } | ||
} | ||
#endregion | ||
|
||
#region public methods | ||
#endregion | ||
|
||
#region explicit interface implementations | ||
IEnumerator<IndexInfo> IEnumerable<IndexInfo>.GetEnumerator() { | ||
return ((IEnumerable<IndexInfo>) indexes).GetEnumerator(); | ||
} | ||
|
||
IEnumerator IEnumerable.GetEnumerator() { | ||
return indexes.GetEnumerator(); | ||
} | ||
#endregion | ||
} | ||
|
||
/// <summary> | ||
/// Represents information about an index. | ||
/// </summary> | ||
public class IndexInfo { | ||
#region private fields | ||
private BsonDocument document; | ||
#endregion | ||
|
||
#region constructors | ||
/// <summary> | ||
/// Creates a new instance of the IndexInfo class. | ||
/// </summary> | ||
/// <param name="document">The BSON document that contains information about the index.</param> | ||
public IndexInfo( | ||
BsonDocument document | ||
) { | ||
this.document = document; | ||
} | ||
#endregion | ||
|
||
#region public properties | ||
/// <summary> | ||
/// Gets whether the dups were dropped when the index was created. | ||
/// </summary> | ||
public bool DroppedDups { | ||
get { | ||
BsonValue value; | ||
if (document.TryGetValue("dropDups", out value)) { | ||
return value.ToBoolean(); | ||
} else { | ||
return false; | ||
} | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Gets whether the index was created in the background. | ||
/// </summary> | ||
public bool IsBackground { | ||
get { | ||
BsonValue value; | ||
if (document.TryGetValue("background", out value)) { | ||
return value.ToBoolean(); | ||
} else { | ||
return false; | ||
} | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Gets whether the index is sparse. | ||
/// </summary> | ||
public bool IsSparse { | ||
get { | ||
BsonValue value; | ||
if (document.TryGetValue("sparse", out value)) { | ||
return value.ToBoolean(); | ||
} else { | ||
return false; | ||
} | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Gets whether the index is unique. | ||
/// </summary> | ||
public bool IsUnique { | ||
get { | ||
BsonValue value; | ||
if (document.TryGetValue("unique", out value)) { | ||
return value.ToBoolean(); | ||
} else { | ||
return false; | ||
} | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Gets the key of the index. | ||
/// </summary> | ||
public IndexKeysDocument Key { | ||
get { | ||
return new IndexKeysDocument(document["key"].AsBsonDocument.Elements); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Gets the name of the index. | ||
/// </summary> | ||
public string Name { | ||
get { | ||
return document["name"].AsString; | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Gets the namespace of the collection that the index is for. | ||
/// </summary> | ||
public string Namespace { | ||
get { | ||
return document["ns"].AsString; | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Gets the version of the index. | ||
/// </summary> | ||
public int Version { | ||
get { | ||
BsonValue value; | ||
if (document.TryGetValue("v", out value)) { | ||
return value.ToInt32(); | ||
} else { | ||
return 0; | ||
} | ||
} | ||
} | ||
#endregion | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters