本文整理汇总了C#中MongoServer.DatabaseExists方法的典型用法代码示例。如果您正苦于以下问题:C# MongoServer.DatabaseExists方法的具体用法?C# MongoServer.DatabaseExists怎么用?C# MongoServer.DatabaseExists使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MongoServer
的用法示例。
在下文中一共展示了MongoServer.DatabaseExists方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestFixtureSetUp
public void TestFixtureSetUp()
{
_server = MongoServer.Create(ConnStr);
if (_server.DatabaseExists(PropSetCollectionsDb))
_server.DropDatabase(PropSetCollectionsDb);
_testDb = _server.GetDatabase(PropSetCollectionsDb);
}
示例2: GetShardInfo
/// <summary>
/// 获得Shard情报
/// </summary>
/// <returns></returns>
public static Dictionary<string, string> GetShardInfo(MongoServer server, string key)
{
var shardInfo = new Dictionary<string, string>();
if (!server.DatabaseExists(ConstMgr.DatabaseNameConfig)) return shardInfo;
var configdb = server.GetDatabase(ConstMgr.DatabaseNameConfig);
if (!configdb.CollectionExists("shards")) return shardInfo;
foreach (var item in configdb.GetCollection("shards").FindAll().ToList())
{
shardInfo.Add(item.GetElement(ConstMgr.KeyId).Value.ToString(),
item.GetElement(key).Value.ToString());
}
return shardInfo;
}
示例3: FixtureSetup
public void FixtureSetup()
{
_mongoServer = MongoServer.Create(ConfigurationManager.ConnectionStrings["mongodb_" + _testDatabaseName].ConnectionString);
var mongoAdminDatbase = _mongoServer.GetDatabase("admin");
mongoAdminDatbase.RunCommand(new CommandDocument(new Dictionary<string, object>
{
{"copydb", "1"},
{"fromdb", "web"},
{"todb", _testDatabaseName},
}));
Assert.That(_mongoServer.DatabaseExists(_testDatabaseName), Is.True);
// TODO: Setup RavenDB
}
示例4: GetShardInfo
/// <summary>
/// 获得Shard情报
/// </summary>
/// <returns></returns>
public static Dictionary<String, String> GetShardInfo(MongoServer server, String Key)
{
var ShardInfo = new Dictionary<String, String>();
if (server.DatabaseExists(DATABASE_NAME_CONFIG))
{
MongoDatabase configdb = server.GetDatabase(DATABASE_NAME_CONFIG);
if (configdb.CollectionExists("shards"))
{
foreach (BsonDocument item in configdb.GetCollection("shards").FindAll().ToList())
{
ShardInfo.Add(item.GetElement(KEY_ID).Value.ToString(), item.GetElement(Key).Value.ToString());
}
}
}
return ShardInfo;
}
示例5: ExecuteMongoSvrCommand
/// <summary>
/// 执行MongoCommand
/// </summary>
/// <param name="mCommandDocument">命令Doc</param>
/// <param name="mongoSvr">目标服务器</param>
/// <returns></returns>
public static CommandResult ExecuteMongoSvrCommand(CommandDocument mCommandDocument, MongoServer mongoSvr)
{
CommandResult mCommandResult = null;
try
{
if (mongoSvr.DatabaseExists(ConstMgr.DatabaseNameAdmin))
{
//Repl的时候,会发生超时问题
mCommandResult = mongoSvr.GetDatabase(ConstMgr.DatabaseNameAdmin).RunCommand(mCommandDocument);
}
else
{
//Replset的时候,没有Admin数据库
BsonDocument AdminDatabaseNotFound = new BsonDocument();
AdminDatabaseNotFound.Add("errmsg", "Admin Database Not Found");
mCommandResult = new CommandResult(AdminDatabaseNotFound);
}
}
catch (MongoCommandException ex)
{
mCommandResult = new CommandResult(ex.Result);
}
catch (TimeoutException)
{
BsonDocument TimeOutDocument = new BsonDocument();
TimeOutDocument.Add("errmsg", "TimeoutException");
mCommandResult = new CommandResult(TimeOutDocument);
}
var e = new RunCommandEventArgs
{
CommandString = mCommandDocument.ToString(),
RunLevel = EnumMgr.PathLevel.Instance,
Result = mCommandResult
};
OnCommandRunComplete(e);
return mCommandResult;
}