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


C# IMongoDatabase.DropCollectionAsync方法代码示例

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


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

示例1: BeforeEachTest

        public void BeforeEachTest()
        {
            var client = new MongoClient("mongodb://localhost:27017");
            var identityTesting = "identity-testing";

            Database = client.GetDatabase(identityTesting);
            Users = Database.GetCollection<IdentityUser>("users");
            Roles = Database.GetCollection<IdentityRole>("roles");

            DatabaseNewApi = client.GetDatabase(identityTesting);
            _UsersNewApi = DatabaseNewApi.GetCollection<IdentityUser>("users");
            _RolesNewApi = DatabaseNewApi.GetCollection<IdentityRole>("roles");

            Database.DropCollectionAsync("users").Wait();
            Database.DropCollectionAsync("roles").Wait();
        }
开发者ID:elizabeth-young,项目名称:aspnet-identity-mongo,代码行数:16,代码来源:UserIntegrationTestsBase.cs

示例2: SetUp

		public void SetUp()
		{
			GlobalContext.Properties.Clear();
			ThreadContext.Properties.Clear();
			MongoUrl url = new MongoUrl("mongodb://localhost/log4net");

			MongoClient client = new MongoClient(url);
			_db = client.GetDatabase(url.DatabaseName);
			_db.DropCollectionAsync(LogsCollectionName);
			_collection = _db.GetCollection<BsonDocument>(LogsCollectionName);
		}
开发者ID:seanfitzg,项目名称:log4mongo-net,代码行数:11,代码来源:MongoDBAppenderTest.cs

示例3: InsertStudentScore

        public static async void InsertStudentScore(IMongoDatabase db)
        {
            var jsonPath = @"C:\Codec\MongoDB\Uni\homework_3_1\students.json";
            var collectionName = "studentscore";
            try
            {
                await db.DropCollectionAsync(collectionName);
                var collection = db.GetCollection<StudentScore>(collectionName);

                using (var streamReader = new StreamReader(jsonPath))
                {
                    string line;
                    while ((line = await streamReader.ReadLineAsync()) != null)
                    {
                        using (var jsonReader = new JsonReader(line))
                        {
                            var context = BsonDeserializationContext.CreateRoot(jsonReader);
                            var document = collection.DocumentSerializer.Deserialize(context);
                            await collection.InsertOneAsync(document);
                        }
                    }
                }
                Console.WriteLine("Successfully Uploaded Students Score");
                Console.WriteLine("Querying all documents");
                await QueryAllDocuments(db, collectionName);

                QueryLowestScore(db, collectionName);


            }
            catch (Exception ex)
            {
                Console.WriteLine("Exception \n\n");
                Console.WriteLine(ex.Message);
            }
        }
开发者ID:ashokkumarreddy1987,项目名称:learnings,代码行数:36,代码来源:Program.cs

示例4: InsertGrades

        public static async void InsertGrades(IMongoDatabase db)
        {
            string jsonPath = @"C:\Codec\MongoDB\Uni\week_2_crud.bf5486e303a0\homework_2_1\grades.json";

            try
            {
                await db.DropCollectionAsync("grades");
                var collection = db.GetCollection<Grades>("grades");
                
                using (var streamReader = new StreamReader(jsonPath))
                {
                 

                    string line;
                    while ((line = await streamReader.ReadLineAsync()) != null)
                    {
                        using (var jsonReader = new JsonReader(line))
                        {
                            var context = BsonDeserializationContext.CreateRoot(jsonReader);
                            var document = collection.DocumentSerializer.Deserialize(context);
                            await collection.InsertOneAsync(document);
                        }
                    }
                }
                Console.WriteLine("Successfully Uploaded Grades");
                Console.WriteLine("Querying all documents");
               
                await QueryAllDocuments(db, "grades");

            }
            catch (Exception ex)
            {
                Console.WriteLine("Exception \n\n");
                Console.WriteLine(ex.Message);
            }
        }
开发者ID:ashokkumarreddy1987,项目名称:learnings,代码行数:36,代码来源:Program.cs


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