当前位置: 首页>>代码示例>>C#>>正文


C# MongoUrlBuilder.ToServerSettings方法代码示例

本文整理汇总了C#中MongoDB.Driver.MongoUrlBuilder.ToServerSettings方法的典型用法代码示例。如果您正苦于以下问题:C# MongoUrlBuilder.ToServerSettings方法的具体用法?C# MongoUrlBuilder.ToServerSettings怎么用?C# MongoUrlBuilder.ToServerSettings使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在MongoDB.Driver.MongoUrlBuilder的用法示例。


在下文中一共展示了MongoUrlBuilder.ToServerSettings方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Connect

 public static CountersDatabase Connect(string mongoUrl)
 {
     MongoUrlBuilder builder = new MongoUrlBuilder(mongoUrl);
     builder.SocketTimeout = new TimeSpan(0, 30, 0);
     //builder.Server = port.HasValue ? new MongoServerAddress(host, port.Value) : new MongoServerAddress(host);
     MongoServer server = MongoServer.Create(builder.ToServerSettings());
     server.Connect();
     MongoDatabase db = server.GetDatabase(builder.DatabaseName);
     return new CountersDatabase(server, db);
 }
开发者ID:demonix,项目名称:iPoint.ServiceStatistics,代码行数:10,代码来源:CountersDatabase.cs

示例2: MongoUrl

 /// <summary>
 /// Creates a new instance of MongoUrl.
 /// </summary>
 /// <param name="url">The URL containing the settings.</param>
 public MongoUrl(
     string url
 ) {
     var builder = new MongoUrlBuilder(url); // parses url
     serverSettings = builder.ToServerSettings().FrozenCopy();
     this.waitQueueMultiple = builder.WaitQueueMultiple;
     this.waitQueueSize = builder.WaitQueueSize;
     this.databaseName = builder.DatabaseName;
     this.url = builder.ToString(); // keep canonical form
 }
开发者ID:zxy050,项目名称:mongo-csharp-driver,代码行数:14,代码来源:MongoUrl.cs

示例3: BulkMongo

        public void BulkMongo(List<FlowControlOneMs> fcom)
        {
            var connectionString = "mongodb://localhost/?safe=true"; // TODO: make this configurable

            var mongoUrlBuilder = new MongoUrlBuilder(connectionString);
            var serverSettings = mongoUrlBuilder.ToServerSettings();
            if (!serverSettings.SafeMode.Enabled)
            {
                serverSettings.SafeMode = SafeMode.True;
            }

            var mongo = MongoServer.Create(serverSettings);
            var db = mongo["guangzhou_gb"];

            db.DropCollection("FlowControlOneMs");
            var collection = db["FlowControlOneMs"];

            collection.InsertBatch(fcom);
        }
开发者ID:sridhar19091986,项目名称:pcapsctpspliter,代码行数:19,代码来源:FlowControlOneMs.cs

示例4: GetMongoCollection

        public static MongoCollection GetMongoCollection(string mongo_conn, string mongodb_collection_name, bool delete_col)
        {
            var connectionString = mongo_conn;

            var mongoUrlBuilder = new MongoUrlBuilder(connectionString);
            var serverSettings = mongoUrlBuilder.ToServerSettings();
            if (!serverSettings.SafeMode.Enabled)
            {
                serverSettings.SafeMode = SafeMode.True;
            }

            var mongo = MongoServer.Create(serverSettings);
            var db = mongo[ConfigurationManager.AppSettings[mongodb_collection_name].ToString()];

            if (delete_col == true)
                db.DropCollection(mongodb_collection_name);

            var collection = db[mongodb_collection_name];

            return collection;
        }
开发者ID:sridhar19091986,项目名称:pcapsctpspliter,代码行数:21,代码来源:MongoConn.cs

示例5: QueryMongo

        public IQueryable<FlowControlOneMs> QueryMongo()
        {
            var connectionString = "mongodb://localhost/?safe=true"; // TODO: make this configurable

            var mongoUrlBuilder = new MongoUrlBuilder(connectionString);
            var serverSettings = mongoUrlBuilder.ToServerSettings();
            if (!serverSettings.SafeMode.Enabled)
            {
                serverSettings.SafeMode = SafeMode.True;
            }

            var mongo = MongoServer.Create(serverSettings);

            var db = mongo["guangzhou_gb"];
            var collection = db.GetCollection("FlowControlOneMs");

            var query = from p in collection.AsQueryable<FlowControlOneMs>()
                        select p;

            return query;
        }
开发者ID:sridhar19091986,项目名称:pcapsctpspliter,代码行数:21,代码来源:FlowControlOneMs.cs

示例6: test

        public static void test()
        {
            var connectionString = "mongodb://localhost/?safe=true"; // TODO: make this configurable

            var mongoUrlBuilder = new MongoUrlBuilder(connectionString);
            var serverSettings = mongoUrlBuilder.ToServerSettings();
            if (!serverSettings.SafeMode.Enabled)
            {
                serverSettings.SafeMode = SafeMode.True;
            }

            var mongo = MongoServer.Create(serverSettings);
            var db = mongo["csharpdriverunittests"];
            var collection = db["movies"];

            var movies = new List<Movie>
            {
            new Movie { Title="The Perfect Developer",
                    Category="SciFi", Minutes=118 },
            new Movie { Title="Lost In Frankfurt am Main",
                    Category="Horror", Minutes=122 },
            new Movie { Title="The Infinite Standup",
                    Category="Horror", Minutes=341 }
            };
            collection.InsertBatch(movies);

            string map = @"
            function() {
            var movie = this;
            emit(movie.Category, { count: 1, totalMinutes: movie.Minutes });
            }";

            string reduce = @"
            function(key, values) {
            var result = {count: 0, totalMinutes: 0 };

            values.forEach(function(value){
            result.count += value.count;
            result.totalMinutes += value.totalMinutes;
            });

            return result;
            }";

            string finalize = @"
            function(key, value){

              value.average = value.totalMinutes / value.count;
              return value;

            }";
            //var linq = from p in collection[""]
            //           select t;

            var options = new MapReduceOptionsBuilder();
            options.SetFinalize(finalize);
            options.SetOutput(MapReduceOutput.Inline);
            var results = collection.MapReduce(map, reduce, options);

            foreach (var result in results.GetResults())
            {
                Console.WriteLine(result.ElementAt(0).Name);
            }
        }
开发者ID:sridhar19091986,项目名称:pcapsctpspliter,代码行数:64,代码来源:Class2.cs

示例7: test

        public static void test()
        {
            var connectionString = "mongodb://localhost/?safe=true"; // TODO: make this configurable

            var mongoUrlBuilder = new MongoUrlBuilder(connectionString);
            var serverSettings = mongoUrlBuilder.ToServerSettings();
            if (!serverSettings.SafeMode.Enabled)
            {
                serverSettings.SafeMode = SafeMode.True;
            }

            var mongo = MongoServer.Create(serverSettings);
            var db = mongo["guangzhou_gb"];
            var collection = db["Gi_Get2x_Multi"];

            string map = @"
            function() {
            var abc = this;
            emit(abc.URI_Main, { count: 1, totalMinutes: 0,totalCount:0 });
            }

            }"
                ;

            string reduce = @"

            function(key, values) {
            var result = {count: 0, totalMinutes: 0,totalCount:0 };

            values.forEach(function(value){
            result.count += value.count;
            result.totalMinutes += value.totalMinutes ;

            });

            return result;
            }"
                ;

               //db.RunCommand
            var abbsum = db["Gi_Get2x_Multi"].FindAll().Count();

            string cmd = @"
                db.Gi_Get2x_Multi.aggregate([
             { $group: {_id:null,
            total:{$sum:'$Get2x'} } }
            ])
            ";
            //CommandResult cr = new CommandResult();
            var comd = db.RunCommandAs(typeof(CommandResult), cmd);

            string finalize = @"

            function(key, value){

            value.average =value.count / " +     comd.Response.AsBsonArray[0].ToString()+ @";
            value.totalCount=" + abbsum.ToString() + @"

              return value;

            }"
                ;

            //
            //var query=QueryBuilde
            IMongoSortBy abc = SortBy.Descending("value.count");
            IMongoQuery query=Query.EQ("value.count",1);
            //MapReduceOutput outname=

               // var abc = "{ \"sort\" : { \"value.count\" : 1} }";

            //MapReduceOutput out=new

            Console.WriteLine(abc.ToString());
            var options = new MapReduceOptionsBuilder();
            //options.SetScope(
            //options.SetQuery(query);//
               // options.SetSortOrder(abc);
            //options.SetLimit(2);
            //options.SetKeepTemp(true);
            options.SetFinalize(finalize);
            options.SetOutput("tempppp");

            var results = collection.MapReduce(map, reduce, options);

            Console.WriteLine(results.Command);
            //results.Command.ToString();

            // var resultss = results.GetResults().OrderByDescending(e => e.Elements.Select["count"]).Take(100);

            var resultss = db["tempppp"].FindAll().SetSortOrder(abc).SetLimit(10);
            //var resultss = results.GetResults().OrderByDescending(p => "value.count").Take(10);

            foreach (var result in resultss )
            {
                Console.WriteLine(result);
            }
        }
开发者ID:sridhar19091986,项目名称:pcapsctpspliter,代码行数:98,代码来源:MapReduceTest.cs


注:本文中的MongoDB.Driver.MongoUrlBuilder.ToServerSettings方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。