本文整理汇总了C#中MongoCollection.Save方法的典型用法代码示例。如果您正苦于以下问题:C# MongoCollection.Save方法的具体用法?C# MongoCollection.Save怎么用?C# MongoCollection.Save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MongoCollection
的用法示例。
在下文中一共展示了MongoCollection.Save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CoverDB
public static void CoverDB(string player, MongoCollection oldPlayer, MongoCollection newPlayer)
{
Console.WriteLine("正在合并:" + player);
int show = 0;
int count = 0;
var dates = oldPlayer.FindAllAs<BsonDocument>();
foreach (var v in dates)
{
BsonValue key;
if (v.TryGetValue("_id", out key))
{
if (newPlayer.Count(Query.EQ("_id", key)) <= 0)
{
count++;
newPlayer.Save(v);
}
}
show++;
if (show % 1000 == 0)
{
Console.WriteLine("正在合并:" + show);
}
}
Console.WriteLine(player + ":" + count);
}
示例2: AddUserEx
/// <summary>
/// Adds a user to this database.
/// </summary>
/// <param name="user">The user.</param>
public static void AddUserEx(MongoCollection Col, User user)
{
var document = Col.FindOneAs<BsonDocument>(Query.EQ("user", user.Username));
if (document == null)
{
document = new BsonDocument("user", user.Username);
}
document["roles"] = user.roles;
if (document.Contains("readOnly"))
{
document.Remove("readOnly");
}
//必须要Hash一下Password
document["pwd"] = MongoUser.HashPassword(user.Username, user.Password);
//OtherRole 必须放在Admin.system.users里面
if (Col.Database.Name == MongoDbHelper.DATABASE_NAME_ADMIN)
{
document["otherDBRoles"] = user.otherDBRoles;
}
if (string.IsNullOrEmpty(user.Password))
{
document["userSource"] = user.userSource;
}
Col.Save(document);
}
示例3: UpdateDocument
public override void UpdateDocument(MongoCollection<BsonDocument> collection, BsonDocument document) {
string id = document.GetElement(DayStackStatsRepository.FieldNames.Id).Value.AsString;
string[] parts = id.Split('/');
if (parts.Length != 2)
return;
string errorStackId = parts[0];
var stackCollection = Database.GetCollection(ErrorStackRepository.CollectionName);
var errorStack = stackCollection.FindOne(Query.EQ(ErrorStackRepository.FieldNames.Id, new BsonObjectId(new ObjectId(errorStackId))));
if (errorStack != null) {
var projectId = errorStack.GetElement(ErrorStackRepository.FieldNames.ProjectId).Value;
document.Set(DayStackStatsRepository.FieldNames.ProjectId, projectId);
}
document.Set(DayStackStatsRepository.FieldNames.ErrorStackId, new BsonObjectId(new ObjectId(errorStackId)));
var emptyBlocks = new List<BsonElement>();
BsonDocument minuteBlocks = document.GetValue(DayStackStatsRepository.FieldNames.MinuteStats).AsBsonDocument;
foreach (BsonElement b in minuteBlocks.Elements) {
if (b.Value.AsInt32 == 0)
emptyBlocks.Add(b);
}
foreach (BsonElement b in emptyBlocks)
minuteBlocks.RemoveElement(b);
collection.Save(document);
}
示例4: UpdateDocument
public override void UpdateDocument(MongoCollection<BsonDocument> collection, BsonDocument document) {
bool renamed = false;
BsonDocument currentDoc = document;
while (currentDoc != null) {
if (currentDoc.Contains(ErrorRepository.FieldNames.ExtendedData)) {
BsonValue extendedData = currentDoc.GetElement(ErrorRepository.FieldNames.ExtendedData).Value;
if (extendedData.IsBsonArray) {
var newDoc = new BsonDocument(extendedData.AsBsonArray.Where(a => a.AsBsonArray.Count == 2).Select(a => new BsonElement(a.AsBsonArray[0].AsString.Replace('.', '_'), a.AsBsonArray[1])));
currentDoc.Set(ErrorRepository.FieldNames.ExtendedData, newDoc);
extendedData = newDoc;
}
renamed |= extendedData.AsBsonDocument.ChangeName("ExtraExceptionProperties", ExtendedDataDictionary.EXCEPTION_INFO_KEY);
renamed |= extendedData.AsBsonDocument.ChangeName("ExceptionInfo", ExtendedDataDictionary.EXCEPTION_INFO_KEY);
renamed |= extendedData.AsBsonDocument.ChangeName("TraceInfo", ExtendedDataDictionary.TRACE_LOG_KEY);
}
if (currentDoc.Contains(ErrorRepository.FieldNames.Inner)) {
BsonValue v = currentDoc.GetElement(ErrorRepository.FieldNames.Inner).Value;
currentDoc = !v.IsBsonNull ? v.AsBsonDocument : null;
} else
currentDoc = null;
}
if (renamed)
collection.Save(document);
}
示例5: UpdateDocument
public override void UpdateDocument(MongoCollection<BsonDocument> collection, BsonDocument document)
{
if (document.Contains("ErrorCount"))
document.ChangeName("ErrorCount", "EventCount");
if (document.Contains("TotalErrorCount"))
document.ChangeName("TotalErrorCount", "TotalEventCount");
if (document.Contains("LastErrorDate"))
document.ChangeName("LastErrorDate", "LastEventDate");
if (document.Contains("MaxErrorsPerMonth"))
document.ChangeName("MaxErrorsPerMonth", "MaxEventsPerMonth");
if (document.Contains("SuspensionCode")) {
var value = document.GetValue("SuspensionCode");
document.Remove("SuspensionCode");
SuspensionCode suspensionCode;
if (value.IsString && Enum.TryParse(value.AsString, true, out suspensionCode))
document.Set("SuspensionCode", suspensionCode);
}
collection.Save(document);
}
示例6: UpdateDocument
public override void UpdateDocument(MongoCollection<BsonDocument> collection, BsonDocument document) {
decimal price = 0m;
if (!document.Contains(OrganizationRepository.FieldNames.PlanId))
return;
switch (document.GetValue(OrganizationRepository.FieldNames.PlanId).AsString) {
case "EX_SMALL":
price = BillingManager.SmallPlan.Price;
break;
case "EX_MEDIUM":
price = BillingManager.MediumPlan.Price;
break;
case "EX_LARGE":
price = BillingManager.LargePlan.Price;
break;
}
if (price == 0m)
return;
if (!document.Contains(OrganizationRepository.FieldNames.BillingPrice))
document.Add(OrganizationRepository.FieldNames.BillingPrice, new BsonString(price.ToString()));
else
document.Set(OrganizationRepository.FieldNames.BillingPrice, new BsonString(price.ToString()));
collection.Save(document);
}
示例7: UpdateDocument
public override void UpdateDocument(MongoCollection<BsonDocument> collection, BsonDocument document)
{
var projectIds = document.GetValue("ProjectIds").AsBsonArray.Select(p => p.AsInt32).ToList();
document.Remove("ProjectIds");
document.Add("ProjectIds", new BsonArray(projectIds.Select(x => x.ToString())));
collection.Save(document);
}
示例8: UpdateDocument
public override void UpdateDocument(MongoCollection<BsonDocument> collection, BsonDocument document) {
ObjectId organizationId = document.GetValue(ProjectRepository.FieldNames.OrganizationId).AsObjectId;
var users = Database.GetCollection(UserRepository.CollectionName)
.Find(Query.In(UserRepository.FieldNames.OrganizationIds, new List<BsonValue> {
organizationId
}))
.SetFields(ProjectRepository.FieldNames.Id).ToList();
if (!document.Contains(ProjectRepository.FieldNames.NotificationSettings))
document.Add(ProjectRepository.FieldNames.NotificationSettings, new BsonDocument());
BsonDocument settings = document.GetValue(ProjectRepository.FieldNames.NotificationSettings).AsBsonDocument;
foreach (var user in users) {
var userId = user.GetValue(ProjectRepository.FieldNames.Id).AsObjectId.ToString();
if (!settings.Contains(userId))
settings.Add(userId, new BsonDocument());
var userSettings = settings.GetValue(userId).AsBsonDocument;
if (!userSettings.Contains("SendDailySummary"))
userSettings.Add("SendDailySummary", new BsonBoolean(true));
else
userSettings.Set("SendDailySummary", new BsonBoolean(true));
}
collection.Save(document);
}
示例9: UpdateDocument
public override void UpdateDocument(MongoCollection<BsonDocument> collection, BsonDocument document) {
if (!document.Contains(UserRepository.FieldNames.IsEmailAddressVerified))
document.Add(UserRepository.FieldNames.IsEmailAddressVerified, new BsonBoolean(true));
else
document.Set(UserRepository.FieldNames.IsEmailAddressVerified, new BsonBoolean(true));
collection.Save(document);
}
示例10: UpdateDocument
public override void UpdateDocument(MongoCollection<BsonDocument> collection, BsonDocument document) {
if (document.Contains("OverageHours"))
document.Remove("OverageHours");
if (document.Contains("Usage"))
document.Remove("Usage");
collection.Save(document);
}
示例11: UpdateDocument
public override void UpdateDocument(MongoCollection<BsonDocument> collection, BsonDocument document) {
if (collection.IndexExistsByName("Username_1"))
collection.DropIndexByName("Username_1");
if (document.Contains("Username"))
document.Remove("Username");
collection.Save(document);
}
示例12: UpdateDocument
public override void UpdateDocument(MongoCollection<BsonDocument> collection, BsonDocument document) {
if (!document.Contains(ErrorStackRepository.FieldNames.SignatureInfo))
return;
var signatureInfo = document.GetElement(ErrorStackRepository.FieldNames.SignatureInfo).Value.AsBsonDocument;
bool renamed = signatureInfo.ChangeName("AppPath", "Path");
if (renamed)
collection.Save(document);
}
示例13: UpdateDocument
public override void UpdateDocument(MongoCollection<BsonDocument> collection, BsonDocument document) {
if (document.Contains("OverageDays"))
document.Remove("OverageDays");
document.ChangeName("MaxErrorsPerDay", "MaxErrorsPerMonth");
var maxErrorsPerMonth = document.GetValue("MaxErrorsPerMonth").AsInt32;
if (maxErrorsPerMonth > 0)
document.Set("MaxErrorsPerMonth", maxErrorsPerMonth * 30);
collection.Save(document);
}
示例14: AddEvent
private void AddEvent(ObjectId id, int statusCode, MongoCollection<Entity> collection)
{
var entity = collection.FindOneById(id);
entity.StatusCode = statusCode;
entity.Events.Add(new EntityEvent
{
CreatedAt = DateTime.Now,
Description = Guid.NewGuid().ToString(),
StatusCode = statusCode
});
collection.Save(entity);
}
示例15: UpdateDocument
public override void UpdateDocument(MongoCollection<BsonDocument> collection, BsonDocument document) {
if (!document.Contains(ErrorRepository.FieldNames.RequestInfo))
return;
BsonDocument requestInfo = document.GetElement(ErrorRepository.FieldNames.RequestInfo).Value.AsBsonDocument;
if (!requestInfo.Contains("frm"))
return;
requestInfo.Add(ErrorRepository.FieldNames.PostData, new BsonString(requestInfo.GetElement("frm").Value.ToJson()));
requestInfo.Remove("frm");
collection.Save(document);
}