本文整理汇总了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);
}
示例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: 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);
}
}
示例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;
}
}
示例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;
}
示例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);
}
}
示例13: CreateCollectionIfNecessary
private static void CreateCollectionIfNecessary(MongoDatabase database)
{
if (!database.CollectionExists(CollectionName))
{
database.CreateCollection(CollectionName);
}
}