Skip to content
This repository has been archived by the owner on Dec 30, 2020. It is now read-only.

Commit

Permalink
Use a custom findOne for commands instead of a command collections. T…
Browse files Browse the repository at this point in the history
…his is need, because otherwise later we have to get a new collections for each typed command.
  • Loading branch information
lanwin committed Mar 12, 2010
1 parent faece0f commit 4452213
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions MongoDBDriver/Database.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ namespace MongoDB.Driver
{
public class Database
{
private readonly IMongoCollection<Document> _command;
private readonly Connection _connection;
private DatabaseJS _javascript;
private DatabaseMetaData _metaData;
Expand All @@ -34,7 +33,6 @@ public Database(Connection connection, String name){
//Todo: should be internal
Name = name;
_connection = connection;
_command = this["$cmd"];
}

/// <summary>
Expand Down Expand Up @@ -229,7 +227,7 @@ private Document SendCommandCore(string command){
/// <param name="cmd">The CMD.</param>
/// <returns></returns>
private Document SendCommandCore(Document cmd){
var result = _command.FindOne(cmd);
var result = FindOneCommand<Document>(cmd);
var ok = (double)result["ok"];
if(ok != 1.0){
var msg = string.Empty;
Expand All @@ -242,6 +240,24 @@ private Document SendCommandCore(Document cmd){
return result;
}

/// <summary>
/// Finds the one command.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="spec">The spec.</param>
/// <returns></returns>
private T FindOneCommand<T>(Document spec) where T:class{
var cursor = new Cursor<T>(_connection, Name + ".$cmd", spec??new Document(), -1, 0, null);

foreach(var document in cursor.Documents)
{
cursor.Dispose();
return document;
}

return null;
}

/// <summary>
/// Authenticates the on first request.
/// </summary>
Expand Down

0 comments on commit 4452213

Please sign in to comment.