本文整理汇总了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");
}
示例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");
}
示例3: TestFixture_Setup
public void TestFixture_Setup()
{
_server = new MongoServer();
_db = _server.GetDatabase("TestSuiteDatabase");
DroppedCollectionResponse collResponse = _db.DropCollection("TestClasses");
_coll = _db.GetCollection<TestClass>("TestClasses");
}
示例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);
}
示例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);
}
}
示例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;
}
示例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);
}
}