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


C# MongoDatabase.DropCollection方法代码示例

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


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

示例1: BeforeEachTest

        public void BeforeEachTest()
        {
            var client = new MongoClient("mongodb://localhost:27017");
            Database = client.GetServer().GetDatabase("identity-testing");
            Users = Database.GetCollection<IdentityUser>("users");
            Roles = Database.GetCollection<IdentityRole>("roles");
            IdentityContext = new IdentityContext(Users, Roles);

            Database.DropCollection("users");
            Database.DropCollection("roles");
        }
开发者ID:Malkiat-Singh,项目名称:aspnet-identity-mongo,代码行数:11,代码来源:UserIntegrationTestsBase.cs

示例2: BeforeEachTest

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

			Database = client.GetServer().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.DropCollection("users");
			Database.DropCollection("roles");
		}
开发者ID:shoebsd,项目名称:aspnet-identity-mongo,代码行数:16,代码来源:UserIntegrationTestsBase.cs

示例3: TestFixture_Setup

 public void TestFixture_Setup()
 {
     _server = new MongoServer();
     _db = _server.GetDatabase("TestSuiteDatabase");
     DroppedCollectionResponse collResponse = _db.DropCollection("TestClasses");
     _coll = _db.GetCollection<TestClass>("TestClasses");
 }
开发者ID:sdether,项目名称:NoRM,代码行数:7,代码来源:WhereQualifierTests.cs

示例4: MongoDocumentWriter

        public MongoDocumentWriter(string connectionString, string databaseName, string collectionName)
        {
            var id = new ObjectId();
            var server = new MongoClient(connectionString).GetServer();
            _db = server.GetDatabase(databaseName);

            if (_db.CollectionExists(collectionName))
                _db.DropCollection(collectionName);

            _db.CreateCollection(collectionName);
            _collection = _db.GetCollection(collectionName);
        }
开发者ID:breuben,项目名称:Csv2Mongo,代码行数:12,代码来源:MongoDocumentWriter.cs

示例5: RankAchievements

        public override void RankAchievements()
        {
            string databaseName = "Achievements";

            if (ConfigurationManager.AppSettings["MongoDbName"] != null)
            {
                databaseName = ConfigurationManager.AppSettings["MongoDbName"];
            }
            // TODO : Get connection string from app.config
            // TODO : Get database name from app.config

            MongoServer server = MongoServer.Create(ConfigurationManager.ConnectionStrings["AchievementDatabase"].ConnectionString);

            //server.Settings.SocketTimeout = new TimeSpan(TimeSpan.TicksPerMinute * 5);

            _database = server.GetDatabase(databaseName);

            if (_database.CollectionExists(AchievementUsageCollectionName))
            {
                _database.DropCollection(AchievementUsageCollectionName);
            }

            MongoCollection<Character> characterCollection = _database.GetCollection<Character>(MongoCharacterRepository.CollectionName);

            characterCollection.MapReduce(_mapFunction, _reduceFunction, MapReduceOptions.SetOutput(AchievementUsageCollectionName));

            MongoCollection<BsonDocument> ranking = _database.GetCollection(AchievementUsageCollectionName);
            IList<BsonDocument> rankings = ranking.FindAll().SetSortOrder(SortBy.Descending("value.count")).ToList();
            int maxRank = 0;
            for (int i = 0; i < rankings.Count; i++)
            {
                int achievementId = Convert.ToInt32(rankings[i]["_id"].AsDouble);
                Achievement achievement = AchievementRepository.Find(achievementId);
                if (achievement != null)
                {
                    achievement.Rank = i + 1;
                    maxRank++;
                    AchievementRepository.Save(achievement);
                }
            }

            var unrankedAchievements = AchievementRepository.FindAll().Where(a => a.Rank == 0);
            foreach (Achievement unrankedAchievement in unrankedAchievements)
            {
                unrankedAchievement.Rank = int.MaxValue;
                AchievementRepository.Save(unrankedAchievement);
            }
        }
开发者ID:blat001,项目名称:Achievement-Sherpa,代码行数:48,代码来源:MongoAchievementService.cs

示例6: Run

 /// <summary>
 /// Executes the command and returned the output documents
 /// </summary>
 /// <param name="db">The db to execute the command on</param>
 /// <returns></returns>
 public List<BsonDocument> Run(MongoDatabase db)
 {
     var ret = db.RunCommand(Build(), true);
     if (ret.Ok && ret.HasResponse)
     {
         callOk = true;
         if (ret.Response.Has("results"))
         {
             var docs = (ret.Response["results"] as object[])
                             .OfType<BsonDocument>()
                             .ToList();
             if (!string.IsNullOrEmpty(keyFieldName))
             {
                 var key = "value." + keyFieldName;
                 foreach (var doc in docs)
                 {
                     doc[key] = doc["id"] = doc["_id"]; //id value is set to conform with the doc if read via select
                 }
                 return docs.Select(x => x["value"]).OfType<BsonDocument>().ToList();
             }
             //if no key is specified, return the entire document. not just the value
             return docs;
         }
         else
         {
             var col = (string)ret.Response["result"];
             var docs = db.GetCollection(col).Find().Select().OfType<BsonDocument>().ToList();
             db.DropCollection(col);
             if (!string.IsNullOrEmpty(keyFieldName))
             {
                 var key = "value." + keyFieldName;
                 foreach (var doc in docs)
                 {
                     doc[key] = doc["id"];
                 }
                 return docs.Select(x=>x["value"]).OfType<BsonDocument>().ToList();
             }
             //if no key is specified, return the entire document, not just the value
             return docs;
         }
     }
     callOk = false;
     //todo: log the error
     return null;
 }
开发者ID:ritcoder,项目名称:CSMongo,代码行数:50,代码来源:MapReduceParameters.cs

示例7: DropAndCreateCollections

        private static void DropAndCreateCollections(MongoDatabase db, string[] collections)
        {
            string[] names = Enumerable.ToArray<string>(db.GetCollectionNames());
            foreach (string name in names)
            {
                if (collections.Contains(name))
                {
                    db.DropCollection(name);
                }
            }

            foreach (string collection in collections)
            {
                db.CreateCollection(collection);
            }
        }
开发者ID:asanyaga,项目名称:BuildTest,代码行数:16,代码来源:DB_TestingHelper.cs


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