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


C# MongoDatabase.CollectionExists方法代码示例

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


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

示例1: Initializer

        public Initializer(MongoDatabase database)
        {
            _database = database;

            if (!_database.CollectionExists(Collections.USERS))
                _database.CreateCollection(Collections.USERS);

            if (!_database.CollectionExists(Collections.TODOS))
                _database.CreateCollection(Collections.TODOS);
        }
开发者ID:leftofnull,项目名称:mongodb-todo,代码行数:10,代码来源:Initializer.cs

示例2: MongoAtHomeDataRepository

        public MongoAtHomeDataRepository()
        {
            _mongoServer = MongoServer.Create(ApplicationSettings.MongoDBConnectionString);
            _mongoDatabase = _mongoServer.GetDatabase(_dbName);

            if (!_mongoDatabase.CollectionExists("clientinformation"))
                _mongoDatabase.CreateCollection("clientinformation");

            if (!_mongoDatabase.CollectionExists("workunit"))
                _mongoDatabase.CreateCollection("workunit");
        }
开发者ID:chandermani,项目名称:IronFoundryAtHome,代码行数:11,代码来源:MongoAtHomeDataRepository.cs

示例3: Initialize

        void Initialize()
        {
            _server = MongoServer.Create(_configuration.Url);
            _database = _server.GetDatabase(_configuration.DefaultDatabase);
            if (!_database.CollectionExists(CollectionName))
                _database.CreateCollection(CollectionName);

            _collection = _database.GetCollection(CollectionName);

            if (!_database.CollectionExists(IncrementalKeysCollectionName))
                _database.CreateCollection(IncrementalKeysCollectionName);

            _incrementalKeysCollection = _database.GetCollection(IncrementalKeysCollectionName);
        }
开发者ID:JoB70,项目名称:Bifrost,代码行数:14,代码来源:EventStore.cs

示例4: Initialize

        void Initialize()
        {
            _server = MongoServer.Create(_configuration.Url);
            _database = _server.GetDatabase(_configuration.DefaultDatabase);
            if (!_database.CollectionExists(CollectionName))
                _database.CreateCollection(CollectionName);

            _collection = _database.GetCollection<EventSubscription>(CollectionName);
        }
开发者ID:JoB70,项目名称:Bifrost,代码行数:9,代码来源:EventSubscriptions.cs

示例5: connect

 static void connect()
 {
     server = MongoServer.Create(dbURL);
     database = server.GetDatabase("void");
     if (!database.CollectionExists(dbName))
     {
         database.CreateCollection(dbName);
     }
 }
开发者ID:andrewmunro,项目名称:Void,代码行数:9,代码来源:MongoHelper.cs

示例6: CreateCollectionWithOptions

 /// <summary>
 ///     带有参数的CreateOption
 /// </summary>
 /// <param name="strObjTag"></param>
 /// <param name="collectionName"></param>
 /// <param name="option"></param>
 /// <param name="mongoDb"></param>
 /// <returns></returns>
 public static bool CreateCollectionWithOptions(string strObjTag, string collectionName,
     CollectionOptionsBuilder option, MongoDatabase mongoDb)
 {
     //不支持中文 JIRA ticket is created : SERVER-4412
     //SERVER-4412已经在2013/03解决了
     //collection names are limited to 121 bytes after converting to UTF-8. 
     if (mongoDb == null) return false;
     if (mongoDb.CollectionExists(collectionName)) return false;
     mongoDb.CreateCollection(collectionName, option);
     return true;
 }
开发者ID:jango2015,项目名称:MongoCola,代码行数:19,代码来源:Collection.cs

示例7: ObjectStore

        public ObjectStore()
        {
            var connectionString = ConfigurationManager.AppSettings.Get("MONGOLAB_URI");
            var server = MongoServer.Create(connectionString);
            _database = server.GetDatabase("appharbor_a6a88884-0e19-42c8-92ed-6ec23821b99d");

            var exists = _database.CollectionExists(SubscribersKey);
            if (!exists)
            {
                _database.CreateCollection(SubscribersKey);
            }
        }
开发者ID:estien,项目名称:WP7Data,代码行数:12,代码来源:ObjectStore.cs

示例8: 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

示例9: 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

示例10: CreateCollection

 //public MongoDatabase GetDatabase()
 //{
 //    //MongoServer server = MongoServer.Create(ConnectionString);
 //    //MongoCredential cred = new MongoCredential("test",
 //    ////MongoCredentials cred = new MongoCredentials(UserName, PassWord);
 //    //MongoDatabase db = server.GetDatabase(DatabaseName, cred);
 //    //return db;
 //}
 public bool CreateCollection(MongoDatabase db, string collectionname)
 {
     try
     {
         if (db.CollectionExists(collectionname) == false)
         {
             db.CreateCollection(collectionname);
             return true;
         }
         else
         {
             return true;
         }
     }
     catch (Exception)
     {
         return false;
     }
 }
开发者ID:ercrgg,项目名称:MongoBannerlinkExtraction,代码行数:27,代码来源:mongodb.cs

示例11: GetCreateCollection

 /// <summary>
 /// Retrieve existing or create new collection
 /// </summary>
 /// <param name="mongoDatabase">The mongo database.</param>
 /// <param name="collectionName">Name of the collection.</param>
 /// <returns></returns>
 private static MongoCollection<BsonDocument> GetCreateCollection(MongoDatabase mongoDatabase, string collectionName)
 {
     MongoCollection<BsonDocument> mongoCollection;
     if (mongoDatabase.CollectionExists(collectionName))
     {
         mongoCollection = mongoDatabase.GetCollection<BsonDocument>(collectionName);
     }
     else
     {
         mongoCollection = mongoDatabase.GetCollection<BsonDocument>(collectionName);
         mongoCollection.EnsureIndex(IndexKeys.Ascending(UniqueKeyFieldName), IndexOptions.SetUnique(true));
     }
     return mongoCollection;
 }
开发者ID:KlaudWerk,项目名称:WSHumanTask,代码行数:20,代码来源:MongoPropertySetCollection.cs

示例12: VerifyCollection

 /// <summary>
 /// Verifies the the MongoDatabase collection exists or creates it if it doesn't.
 /// </summary>
 /// <param name="logDb"></param>
 protected void VerifyCollection(MongoDatabase logDb)
 {
     if (!logDb.CollectionExists(_collectionName))
     {
         logDb.CreateCollection(_collectionName, _collectionCreationOptions);
     }
 }
开发者ID:rmoudy,项目名称:serilog,代码行数:11,代码来源:MongoDBSink.cs

示例13: CreateCollectionIfNecessary

 private static void CreateCollectionIfNecessary(MongoDatabase database)
 {
     if (!database.CollectionExists(CollectionName))
     {
         database.CreateCollection(CollectionName);
     }
 }
开发者ID:JohannesHoppe,项目名称:WebNoteNoSQL,代码行数:7,代码来源:HowToReadAndWriteWithMongoDB.cs


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