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


C# MongoDatabase.CreateCollection方法代码示例

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


在下文中一共展示了MongoDatabase.CreateCollection方法的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: 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

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

示例11: CreateCollectionIfNecessary

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

示例12: Up

 public override void Up(MongoDatabase database)
 {
     database.CreateCollection("Users");
 }
开发者ID:Islandskiy,项目名称:Ognom.Migrator,代码行数:4,代码来源:m002_CreateUsersCollection.cs

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