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


C# MongoClient.GetCollection方法代码示例

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


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

示例1: Any

 public void Any(KnockPostV1 request)
 {
     var db = new MongoClient().GetDatabase("test");
     var collection = db.GetCollection<Potato>("KnockKnock");
     collection.FindOneAndReplace(Builders<Potato>.Filter.Eq(k => k.Id, request.Knock.Id), new Potato(request.Knock),
         new FindOneAndReplaceOptions<Potato, Potato>() { IsUpsert = true });
 }
开发者ID:mkonkolowicz,项目名称:KnockKnock,代码行数:7,代码来源:KnockKnockMongo.cs

示例2: Aggregate_with_query

        public void Aggregate_with_query()
        {
            var startDate = GetStartDate();
            var endDate = GetEndDate();

            var duration = new TimeSpan(endDate.Ticks - startDate.Ticks);
            var maxCount = duration.TotalMinutes / delta.TotalMinutes;

            var stopWatch = new Stopwatch();
            var dataBase = new MongoClient("mongodb://localhost").GetServer().GetDatabase("MapReduce");
            var sessions = dataBase.GetCollection<Session>("Sessions");

            stopWatch.Start();
            var statistic = new List<StatisticItem>();

            for (int i = 0; i < maxCount; i++)
            {
                var startStroke = startDate.AddMinutes(delta.Minutes * i);
                var endStroke = startStroke.AddMinutes(delta.Minutes);
                statistic.Add(this.GetStatisticItem(startStroke, endStroke, sessions));
            }
            stopWatch.Stop();
            foreach (var statItem in statistic)
            {
                Trace.WriteLine(statItem.DateTime + " " + statItem.Count);
            }
            Trace.WriteLine("Aggregation: " + stopWatch.ElapsedTicks);
        }
开发者ID:namesecured,项目名称:MapReduce,代码行数:28,代码来源:AggregationTests.cs

示例3: Aggregate_with_map_reduce

        public void Aggregate_with_map_reduce()
        {
            var dataBase = new MongoClient("mongodb://localhost").GetServer().GetDatabase("MapReduce");
            var sessions = dataBase.GetCollection<Session>("Sessions");

            BsonJavaScript map = new BsonJavaScript(Scipts.map);
            BsonJavaScript reduce = new BsonJavaScript(Scipts.reduce);
            var result = sessions.MapReduce(map, reduce);
        }
开发者ID:namesecured,项目名称:MapReduce,代码行数:9,代码来源:AggregationTests.cs

示例4: RequestResponsePairQueryService

        public RequestResponsePairQueryService(IConfig config)
        {
            var url = MongoUrl.Create(config.ProxyDbConnectionString);
            var db = new MongoClient(url)
                .GetServer()
                .GetDatabase(url.DatabaseName);

            _collection = db.GetCollection<RequestResponsePair>();
        }
开发者ID:ryanande,项目名称:ApiProxy,代码行数:9,代码来源:RequestResponsePairQueryService.cs

示例5: MongoDBRevisionStorage

		public MongoDBRevisionStorage(string connectionString)
		{
			ConnectionString = connectionString;

			var mongoUrl = MongoUrl.Create(connectionString);
			var database = new MongoClient(mongoUrl).GetDatabase(mongoUrl.DatabaseName);

			_revisions = database.GetCollection<RevisionModel>("revisions");
		}
开发者ID:sFedyashov,项目名称:BuildRevisionCounter,代码行数:9,代码来源:MongoDBRevisionStorage.cs

示例6: UseCaseQueryService

        public UseCaseQueryService(IConfig config)
        {
            var url = MongoUrl.Create(config.ProxyDbConnectionString);
            var db = new MongoClient(url)
                .GetServer()
                .GetDatabase(url.DatabaseName);

            _collection = db.GetCollection<UseCase>();
        }
开发者ID:ryanande,项目名称:ApiProxy,代码行数:9,代码来源:UseCaseQueryService.cs

示例7: UseCaseUpdateTask

        public UseCaseUpdateTask(IConfig config, IDataList<UseCase> useCases)
        {
            var url = new MongoUrl(config.ProxyDbConnectionString);
            var db = new MongoClient(url)
                .GetServer()
                .GetDatabase(url.DatabaseName);

            _collection = db.GetCollection<UseCase>("UseCase");
            _useCases = useCases;
        }
开发者ID:hpence,项目名称:ApiProxy,代码行数:10,代码来源:UseCaseUpdateTask.cs

示例8: MongoDBUserStorage

		public MongoDBUserStorage(string connectionString)
		{
			ConnectionString = connectionString;

			var mongoUrl = MongoUrl.Create(connectionString);
			var database = new MongoClient(mongoUrl).GetDatabase(mongoUrl.DatabaseName);

			_users = database.GetCollection<UserModel>("users");

			Task.Run(() => SetUp()).Wait();
		}
开发者ID:sFedyashov,项目名称:BuildRevisionCounter,代码行数:11,代码来源:MongoDBUserStorage.cs

示例9: Aggregate

        public void Aggregate()
        {
            var dataBase = new MongoClient("mongodb://localhost").GetServer().GetDatabase("MapReduce");
            var collection = dataBase.GetCollection<Session>("Sessions");

            var match = GetMatchOperator(GetStartDate(), GetEndDate());
            var project = GetProjectOperator(GetStartDate());

            var pipeline = new[] { match, project };
            var result = collection.Aggregate(pipeline);
            var matching = result.ResultDocuments.Count();
        }
开发者ID:namesecured,项目名称:MapReduce,代码行数:12,代码来源:AggregationTests.cs

示例10: AddMessage

        public static void AddMessage(string username, string text)
        {
            MongoDatabase db = new MongoClient("mongodb://daniel:[email protected]:61548/chat-db")
                .GetServer()
                .GetDatabase("chat-db");

            var messagesCollection = db.GetCollection<Message>("messages");

            var message = new Message { Date = DateTime.Now, Username = username, Text = text };

            messagesCollection.Insert(message);
        }
开发者ID:StanislavBozhilov,项目名称:SoftwareUniversity,代码行数:12,代码来源:Program.cs

示例11: mainAsync

        public static async Task mainAsync()
        {
            var db = new MongoClient().GetDatabase("school");
            var collection = db.GetCollection<BsonDocument>("students");
            var list = await collection.Find(new BsonDocument()).ToListAsync();
            var newList = new List<BsonDocument>();

            list.ForEach(data => newList.Add(dropScore(data)));

            await db.DropCollectionAsync("students");
            await db.CreateCollectionAsync("students");
            await collection.InsertManyAsync(newList);
        }
开发者ID:ronnysuero,项目名称:MongoDB-CSharp,代码行数:13,代码来源:Program.cs

示例12: MainAsync

        static async Task MainAsync() 
        {
            var database = new MongoClient().GetDatabase("students");
            var collection = database.GetCollection<BsonDocument>("grades");

            List<BsonDocument> listStudents = await collection.Find(new BsonDocument("type", "homework")).ToListAsync();
            
            listStudents.GroupBy(data => data["student_id"]).Select(data => new { student_id = data.Key, score = data.Min(x => x["score"]) }).ToList().ForEach(student =>
            {
                Console.WriteLine(student + " score removed.");
                collection.DeleteOneAsync(new BsonDocument("student_id", student.student_id).Add("score", student.score).Add("type", "homework"));
            });
        }
开发者ID:ronnysuero,项目名称:MongoDB-CSharp,代码行数:13,代码来源:Program.cs

示例13: TableFiller

        public TableFiller(DbSettings configuration)
        {
            Configurations = configuration.collections.Configurations;
            Counters = configuration.collections.Counters;

            ConnectionString = configuration.connectionstring;
            DatabaseName = configuration.database;

            Database = new MongoClient(ConnectionString).GetServer().GetDatabase(DatabaseName);

            var configJson = Database.GetCollection(Configurations).FindOne().ToJson();
            Config = JsonConvert.DeserializeObject<Configurations>(configJson);
        }
开发者ID:Chris2448,项目名称:LightStream,代码行数:13,代码来源:TableFiller.cs

示例14: PrintAllMessages

        public static void PrintAllMessages()
        {
            MongoDatabase db = new MongoClient("mongodb://daniel:[email protected]:61548/chat-db")
                .GetServer()
                .GetDatabase("chat-db");

            var messagesCollection = db.GetCollection<Message>("messages");

            var messages = messagesCollection.FindAll();

            foreach (var message in messages)
            {
                Console.WriteLine("Message:\n User:{0}\n Text: {1}", message.Username, message.Text);
                Console.WriteLine();
            }
        }
开发者ID:StanislavBozhilov,项目名称:SoftwareUniversity,代码行数:16,代码来源:Program.cs

示例15: Main

    static void Main()
    {
        var db = new MongoClient(Connections.Default.MongoCloud).GetServer().GetDatabase("mongochat");
        var messages = db.GetCollection<BsonDocument>("Messages");

        Console.Write("Username: ");
        string username = Console.ReadLine();

        while (true)
        {
            Console.Write("> ");
            string input = Console.ReadLine();

            if (!string.IsNullOrWhiteSpace(input))
                messages.Insert(
                    new BsonDocument { { "Author", username }, { "Text", input }, { "Time", DateTime.Now } });

            var formattedMessages = messages
                .FindAll()
                .Select(m => string.Format("[{0}] {1}: {2}", m["Time"].ToLocalTime(), m["Author"], m["Text"]));

            Console.WriteLine(string.Join(Environment.NewLine, formattedMessages));
        }
    }
开发者ID:MarKamenov,项目名称:TelerikAcademy,代码行数:24,代码来源:MongoChatClient.cs


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