private ToServerSettings ( ) : |
||
Результат |
/// <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 }
// constructors /// <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(); _waitQueueMultiple = builder.WaitQueueMultiple; _waitQueueSize = builder.WaitQueueSize; _databaseName = builder.DatabaseName; _url = builder.ToString(); // keep canonical form }
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); }
/// <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().Freeze(); this.waitQueueMultiple = builder.WaitQueueMultiple; this.waitQueueSize = builder.WaitQueueSize; this.databaseName = builder.DatabaseName; this.url = builder.ToString(); // keep canonical form }
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); }
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; }
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; }
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); } }
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); } }