コード例 #1
0
 /// <summary>
 ///     运行
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void cmdRun_Click(object sender, EventArgs e)
 {
     var map = new BsonJavaScript(ctlMapFunction.Context);
     var reduce = new BsonJavaScript(ctlReduceFunction.Context);
     //TODO:这里可能会超时,失去响应
     //需要设置SocketTimeOut
     MapReduceArgs args = new MapReduceArgs();
     args.MapFunction = map;
     args.ReduceFunction = reduce;
     MapReduceResult mMapReduceResult = SystemManager.GetCurrentCollection().MapReduce(args);
     MongoDbHelper.FillDataToTreeView("MapReduce Result", trvResult, mMapReduceResult.Response);
     trvResult.DatatreeView.BeginUpdate();
     trvResult.DatatreeView.ExpandAll();
     trvResult.DatatreeView.EndUpdate();
 }
コード例 #2
0
ファイル: frmMapReduce.cs プロジェクト: jango2015/MongoCola
 /// <summary>
 ///     运行
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void cmdRun_Click(object sender, EventArgs e)
 {
     var map = new BsonJavaScript(ctlMapFunction.Context);
     var reduce = new BsonJavaScript(ctlReduceFunction.Context);
     //TODO:这里可能会超时,失去响应
     //需要设置SocketTimeOut
     var args = new MapReduceArgs();
     args.MapFunction = map;
     args.ReduceFunction = reduce;
     try
     {
         var mMapReduceResult = RuntimeMongoDbContext.GetCurrentCollection().MapReduce(args);
         UiHelper.FillDataToTreeView("MapReduce Result", trvResult, mMapReduceResult.Response);
         trvResult.DatatreeView.BeginUpdate();
         trvResult.DatatreeView.ExpandAll();
         trvResult.DatatreeView.EndUpdate();
     }
     catch (Exception ex)
     {
         Utility.ExceptionDeal(ex);
     }
 }
コード例 #3
0
ファイル: frmMapReduce.cs プロジェクト: magicdict/MongoCola
 /// <summary>
 ///     运行
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void cmdRun_Click(object sender, EventArgs e)
 {
     var map = new BsonJavaScript(ctlMapFunction.Context);
     var reduce = new BsonJavaScript(ctlReduceFunction.Context);
     //TODO:这里可能会超时,失去响应
     //需要设置SocketTimeOut
     var args = new MapReduceArgs();
     args.MapFunction = map;
     args.ReduceFunction = reduce;
     if (!string.IsNullOrEmpty(ctlFinalizeFunction.Context))
     {
         args.FinalizeFunction = new BsonJavaScript(ctlFinalizeFunction.Context);
     }
     args.OutputMode = (MapReduceOutputMode)cmbOutputMode.SelectedIndex;
     if (!string.IsNullOrEmpty(txtOutputCollectionName.Text)) args.OutputCollectionName = txtOutputCollectionName.Text;
     if (NumLimit.Value != 0) args.Limit = (long)NumLimit.Value;
     args.JsMode = chkjsMode.Checked;
     args.Verbose = chkverbose.Checked;
     args.BypassDocumentValidation = chkbypassDocumentValidation.Checked;
     if (QueryDoc != null) args.Query = new QueryDocument(QueryDoc);
     if (mCollation != null) args.Collation = mCollation;
     try
     {
         var mMapReduceResult = RuntimeMongoDbContext.GetCurrentCollection().MapReduce(args);
         var frm = new frmDataView();
         frm.ShowDocument = mMapReduceResult.Response;
         frm.Title = "MapReduce Result";
         UIAssistant.OpenModalForm(frm, true, true);
     }
     catch (Exception ex)
     {
         Utility.ExceptionDeal(ex);
     }
 }
コード例 #4
0
        public void TestMapReduceInlineWithMaxTime()
        {
            if (_primary.Supports(FeatureId.MaxTime))
            {
                using (var failpoint = new FailPoint(FailPointName.MaxTimeAlwaysTimeout, _server, _primary))
                {
                    if (failpoint.IsSupported())
                    {
                        _collection.RemoveAll();
                        _collection.Insert(new BsonDocument("x", 1)); // make sure collection has at least one document so map gets called

                        failpoint.SetAlwaysOn();
                        var args = new MapReduceArgs
                        {
                            MapFunction = "function() { }",
                            ReduceFunction = "function(key, value) { return 0; }",
                            MaxTime = TimeSpan.FromMilliseconds(1)
                        };
                        Assert.Throws<ExecutionTimeoutException>(() => _collection.MapReduce(args));
                    }
                }
            }
        }
コード例 #5
0
        protected override void BeginProcessing()
        {
            var mc = TargetCollection.Collection as MongoCollection;
            if (mc == null) ThrowNotImplementedForFiles("MapReduce");

            var args = new MapReduceArgs();

            args.JsMode = JSMode;

            args.MapFunction = new BsonJavaScript(Function[0]);
            args.ReduceFunction = new BsonJavaScript(Function[1]);
            if (Function.Length == 3)
                args.FinalizeFunction = new BsonJavaScript(Function[2]);

            if (_Query != null)
                args.Query = _Query;

            if (_SortBy != null)
                args.SortBy = _SortBy;

            if (First > 0)
                args.Limit = First;

            if (Scope != null)
                args.Scope = new ScopeDocument(Scope);

            if (!string.IsNullOrEmpty(OutCollection) && OutMode == MapReduceOutputMode.Inline)
                OutMode = MapReduceOutputMode.Replace;

            // output
            args.OutputMode = OutMode;
            args.OutputDatabaseName = OutDatabase;
            args.OutputCollectionName = OutCollection;

            var result = mc.MapReduce(args);

            if (ResultVariable != null)
                SessionState.PSVariable.Set(ResultVariable, result);

            if (OutMode != MapReduceOutputMode.Inline)
                return;

            var documentAs = _ParameterAs ?? new ParameterAs(null);

            //_131018_160000
            foreach (var it in result.GetInlineResultsAs(documentAs.Type))
                WriteObject(it);
        }
コード例 #6
0
        public void TestMapReduceWriteConcern()
        {
            RequireServer.Check().Supports(Feature.CommandsThatWriteAcceptWriteConcern).ClusterType(ClusterType.ReplicaSet);
            _collection.Drop();
            _collection.Insert(new BsonDocument { { "A", 1 }, { "B", 2 } });
            _collection.Insert(new BsonDocument { { "B", 1 }, { "C", 2 } });
            _collection.Insert(new BsonDocument { { "X", 1 }, { "B", 2 } });
            var writeConcern = new WriteConcern(9);
            var map =
                "function() {\n" +
                "    for (var key in this) {\n" +
                "        emit(key, {count : 1});\n" +
                "    }\n" +
                "}\n";
            var reduce =
                "function(key, emits) {\n" +
                "    total = 0;\n" +
                "    for (var i in emits) {\n" +
                "        total += emits[i].count;\n" +
                "    }\n" +
                "    return {count : total};\n" +
                "}\n";
            var args = new MapReduceArgs
            {
                BypassDocumentValidation = true,
                MapFunction = map,
                ReduceFunction = reduce,
                OutputMode = MapReduceOutputMode.Replace,
                OutputCollectionName = "mrout"
            };

            var exception = Record.Exception(() => _collection.WithWriteConcern(writeConcern).MapReduce(args));

            exception.Should().BeOfType<MongoWriteConcernException>();
        }