當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。