當前位置: 首頁>>代碼示例>>C#>>正文


C# Driver.CommandDocument類代碼示例

本文整理匯總了C#中MongoDB.Driver.CommandDocument的典型用法代碼示例。如果您正苦於以下問題:C# CommandDocument類的具體用法?C# CommandDocument怎麽用?C# CommandDocument使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


CommandDocument類屬於MongoDB.Driver命名空間,在下文中一共展示了CommandDocument類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: EnableSharding

 /// <summary>
 /// 數據庫分片
 /// </summary>
 /// <param name="routeSvr"></param>
 /// <param name="shardingDB"></param>
 /// <returns></returns>
 public static CommandResult EnableSharding(MongoServer routeSvr, String shardingDB)
 {
     CommandDocument mongoCmd = new CommandDocument();
     mongoCmd = new CommandDocument();
     mongoCmd.Add("enablesharding", shardingDB);
     return ExecuteMongoCommand(mongoCmd, routeSvr);
 }
開發者ID:kklik,項目名稱:MagicMongoDBTool,代碼行數:13,代碼來源:MongoDBHelper_Replset.cs

示例2: FillClientStatusToList

        /// <summary>
        /// </summary>
        /// <param name="trvSvrStatus"></param>
        /// <param name="mongoConnClientLst"></param>
        public static void FillClientStatusToList(CtlTreeViewColumns trvSvrStatus,
            Dictionary<string, MongoClient> mongoConnClientLst)
        {
            var srvDocList = new List<BsonDocument>();
            foreach (var mongoSvrKey in mongoConnClientLst.Keys)
            {
                try
                {
                    var mongoClient = mongoConnClientLst[mongoSvrKey];
                    //flydreamer提供的代碼
                    // 感謝 魏瓊東 的Bug信息,一些命令必須以Admin執行
                    if (RuntimeMongoDbContext.GetServerConfigBySvrPath(mongoSvrKey).LoginAsAdmin)
                    {
                        var adminDb = mongoClient.GetDatabase(ConstMgr.DatabaseNameAdmin);
                        //Can't Convert IMongoDB To MongoDB
                        var command = new CommandDocument {{CommandHelper.ServerStatusCommand.CommandString, 1}};

                        var serverStatusDoc =
                            CommandHelper.ExecuteMongoDBCommand(command, adminDb).Response;
                        srvDocList.Add(serverStatusDoc);
                    }
                }
                catch (Exception ex)
                {
                    Utility.ExceptionDeal(ex);
                }
            }
            UiHelper.FillDataToTreeView("Server Status", trvSvrStatus, srvDocList, 0);
            //打開第一層
            foreach (TreeNode item in trvSvrStatus.DatatreeView.Nodes)
            {
                item.Expand();
            }
        }
開發者ID:lizhi5753186,項目名稱:MongoCola,代碼行數:38,代碼來源:FillMongoDB.cs

示例3: TestCodeMissing

        public void TestCodeMissing()
        {
            var command = new CommandDocument("invalid", 1);
            var document = new BsonDocument();
            var result = new CommandResult(command, document);

            Assert.IsFalse(result.Code.HasValue);
        }
開發者ID:wireclub,項目名稱:mongo-csharp-driver,代碼行數:8,代碼來源:CommandResultTests.cs

示例4: ExecuteJsShell

 /// 注意:有些命令可能隻能用在mongos上麵,例如addshard
 /// <summary>
 ///     使用Shell Helper命令
 /// </summary>
 /// <param name="JsShell"></param>
 /// <param name="mongoSvr"></param>
 /// <returns></returns>
 public static CommandResult ExecuteJsShell(String JsShell, MongoServer mongoSvr)
 {
     var ShellCmd = new BsonDocument {{"$eval", new BsonJavaScript(JsShell)}, {"nolock", true}};
     //必須nolock
     var mongoCmd = new CommandDocument();
     mongoCmd.AddRange(ShellCmd);
     return ExecuteMongoSvrCommand(mongoCmd, mongoSvr);
 }
開發者ID:EricBlack,項目名稱:MagicMongoDBTool,代碼行數:15,代碼來源:MongoDBHelper_Command_Run.cs

示例5: ExecuteJsShell

 /// <summary>
 /// 使用Shell Helper命令
 /// </summary>
 /// <param name="JsShell"></param>
 /// <param name="mongoSvr"></param>
 /// <returns></returns>
 public static CommandResult ExecuteJsShell(String JsShell, MongoServer mongoSvr)
 {
     BsonDocument cmd = new BsonDocument();
     cmd.Add("$eval", new BsonJavaScript(JsShell));
     //必須nolock
     cmd.Add("nolock", true);
     CommandDocument mongoCmd = new CommandDocument() { cmd };
     return ExecuteMongoCommand(mongoCmd, mongoSvr);
 }
開發者ID:kklik,項目名稱:MagicMongoDBTool,代碼行數:15,代碼來源:MongoDBHelper_Replset.cs

示例6: TestCode

        public void TestCode()
        {
            var command = new CommandDocument("invalid", 1);
            var document = new BsonDocument("code", 18);
            var result = new CommandResult(command, document);

            Assert.IsTrue(result.Code.HasValue);
            Assert.AreEqual(18, result.Code);
        }
開發者ID:wireclub,項目名稱:mongo-csharp-driver,代碼行數:9,代碼來源:CommandResultTests.cs

示例7: btnSearch_Click

 /// <summary>
 /// 全文檢索功能
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void btnSearch_Click(object sender, EventArgs e)
 {
     var textSearchCommand = new CommandDocument
         {
             { "text", SystemManager.GetCurrentCollection().Name },
             { "search", txtKey.Text }
         };
     CommandResult SearchResult = SystemManager.GetCurrentCollection().Database.RunCommand(textSearchCommand);
     MongoDBHelper.FillDataToTreeView("MapReduce Result", trvResult, SearchResult.Response);
 }
開發者ID:qiezi89,項目名稱:MagicMongoDBTool,代碼行數:15,代碼來源:frmTextSearch.cs

示例8: TestOkMissing

 public void TestOkMissing() {
     var command = new CommandDocument("invalid", true);
     var document = new BsonDocument();
     var result = new CommandResult(command, document);
     try {
         var dummy = result.Ok;
     } catch (MongoCommandException ex) {
         Assert.IsTrue(ex.Message.StartsWith("Command 'invalid' failed: response has no ok element (response: "));
     }
 }
開發者ID:oskysal,項目名稱:mongo-csharp-driver,代碼行數:10,代碼來源:CommandResultTests.cs

示例9: Count

 /// <summary>
 ///     執行Count(指定路勁)
 /// </summary>
 /// <param name="QueryDoc"></param>
 /// <param name="databaseName"></param>
 /// <param name="collectionName"></param>
 /// <returns></returns>
 public static CommandResult Count(BsonDocument QueryDoc, string databaseName, string collectionName)
 {
     //db.runCommand( { aggregate: "people", pipeline: [<pipeline>] } )
     var aggrCmd = new CommandDocument
         {
             new BsonElement("count", new BsonString(collectionName)),
             new BsonElement("query", QueryDoc)
         };
     var aggregateCommand = new MongoCommand(aggrCmd, EnumMgr.PathLevel.Database, databaseName);
     return ExecuteMongoCommand(aggregateCommand);
 }
開發者ID:magicdict,項目名稱:MongoCola,代碼行數:18,代碼來源:DataBaseCommand.cs

示例10: Aggregate

 /// <summary>
 ///     執行聚合
 /// </summary>
 /// <param name="aggregateDoc"></param>
 /// <returns></returns>
 /// <param name="collectionName"></param>
 public static CommandResult Aggregate(BsonArray aggregateDoc, string collectionName)
 {
     //db.runCommand( { aggregate: "people", pipeline: [<pipeline>] } )
     var aggrCmd = new CommandDocument
         {
             new BsonElement("aggregate", new BsonString(collectionName)),
             new BsonElement("pipeline", aggregateDoc)
         };
     var aggregateCommand = new MongoCommand(aggrCmd, EnumMgr.PathLevel.Database);
     return ExecuteMongoCommand(aggregateCommand);
 }
開發者ID:magicdict,項目名稱:MongoCola,代碼行數:17,代碼來源:DataBaseCommand.cs

示例11: TestMaxMessageLengthWhenNotServerSuppliedUsesMaxBsonObjectSizeWhenLargerThanMongoDefaults

        public void TestMaxMessageLengthWhenNotServerSuppliedUsesMaxBsonObjectSizeWhenLargerThanMongoDefaults()
        {
            var command = new CommandDocument("ismaster", 1);
            var document = new BsonDocument
            {
                { "ok", 1 },
                { "maxBsonObjectSize", MongoDefaults.MaxMessageLength }
            };
            var result = new IsMasterResult();
            result.Initialize(command, document);

            Assert.AreEqual(MongoDefaults.MaxMessageLength + 1024, result.MaxMessageLength);
        }
開發者ID:pwelter34,項目名稱:mongo-csharp-driver,代碼行數:13,代碼來源:IsMasterResultTests.cs

示例12: TestMaxMessageLengthWhenServerSupplied

        public void TestMaxMessageLengthWhenServerSupplied()
        {
            var command = new CommandDocument("ismaster", 1);
            var document = new BsonDocument
            {
                { "ok", 1 },
                { "maxMessageSizeBytes", 1000 },
                { "maxBsonObjectSize", 1000 }
            };
            var result = new IsMasterResult();
            result.Initialize(command, document);

            Assert.AreEqual(1000, result.MaxMessageLength);
        }
開發者ID:pwelter34,項目名稱:mongo-csharp-driver,代碼行數:14,代碼來源:IsMasterResultTests.cs

示例13: TestOkMissing

 public void TestOkMissing()
 {
     var command = new CommandDocument("invalid", 1);
     var document = new BsonDocument();
     var result = new CommandResult(document) { Command = command };
     try
     {
         var dummy = result.Ok;
     }
     catch (MongoCommandException ex)
     {
         Assert.IsTrue(ex.Message.StartsWith("Command 'invalid' failed. Response has no ok element (response was ", StringComparison.Ordinal));
     }
 }
開發者ID:annikulin,項目名稱:code-classifier,代碼行數:14,代碼來源:CommandResultTests.cs

示例14: AddSharding

 /// <summary>
 /// 增加數據分片
 /// </summary>
 /// <param name="routeSvr"></param>
 /// <param name="replicaSetName"></param>
 /// <param name="shardingNames"></param>
 /// <returns></returns>
 public static CommandResult AddSharding(MongoServer routeSvr, string replicaSetName, List<string> shardingNames)
 {
     BsonDocument config = new BsonDocument();
     BsonDocument cmd = new BsonDocument();
     BsonDocument host = new BsonDocument();
     string cmdPara = replicaSetName + "/";
     foreach (var item in shardingNames)
     {
         cmdPara += SystemManager.ConfigHelperInstance.ConnectionList[item].IpAddr + ":" + SystemManager.ConfigHelperInstance.ConnectionList[item].Port.ToString() + ",";
     }
     cmdPara = cmdPara.TrimEnd(",".ToCharArray());
     CommandDocument mongoCmd = new CommandDocument();
     mongoCmd.Add("addshard", cmdPara);
     return ExecuteMongoCommand(mongoCmd, routeSvr);
 }
開發者ID:kklik,項目名稱:MagicMongoDBTool,代碼行數:22,代碼來源:MongoDBHelper_Replset.cs

示例15: Aggregate

 public static CommandResult Aggregate(BsonArray AggregateDoc)
 {
     //db.runCommand( { aggregate: "people", pipeline: [<pipeline>] } )
     try
     {
         CommandDocument agg = new CommandDocument();
         agg.Add(new BsonElement("aggregate", new BsonString(SystemManager.GetCurrentCollection().Name)));
         agg.Add(new BsonElement("pipeline", AggregateDoc));
         MongoCommand Aggregate_Command = new MongoCommand(agg, PathLv.DatabaseLV);
         return ExecuteMongoCommand(Aggregate_Command, false);
     }
     catch (Exception ex)
     {
         SystemManager.ExceptionDeal(ex);
         return new CommandResult(new BsonDocument());
     }
 }
開發者ID:qq33357486,項目名稱:MagicMongoDBTool,代碼行數:17,代碼來源:MongoDBHelper_RunCommand.cs


注:本文中的MongoDB.Driver.CommandDocument類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。