本文整理汇总了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);
}
示例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");
}
示例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);
}
示例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);
}
示例5: connect
static void connect()
{
server = MongoServer.Create(dbURL);
database = server.GetDatabase("void");
if (!database.CollectionExists(dbName))
{
database.CreateCollection(dbName);
}
}
示例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;
}
示例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);
}
}
示例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);
}
示例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;
}
}
示例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);
}
}
示例11: CreateCollectionIfNecessary
private static void CreateCollectionIfNecessary(MongoDatabase database)
{
if (!database.CollectionExists(CollectionName))
{
database.CreateCollection(CollectionName);
}
}
示例12: Up
public override void Up(MongoDatabase database)
{
database.CreateCollection("Users");
}
示例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);
}
}