本文整理汇总了C#中BsonDocument.Remove方法的典型用法代码示例。如果您正苦于以下问题:C# BsonDocument.Remove方法的具体用法?C# BsonDocument.Remove怎么用?C# BsonDocument.Remove使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BsonDocument
的用法示例。
在下文中一共展示了BsonDocument.Remove方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RawData
public RawData(BsonDocument bsonDocument)
{
TimestampSent = bsonDocument["timestamp_sent"].ToUniversalTime();
bsonDocument.Remove("timestamp_sent");
TimestampReceived = bsonDocument["timestamp_received"].ToUniversalTime();
bsonDocument.Remove("timestamp_received");
_sensorsDatas = BsonSerializer.Deserialize<SensorData>(bsonDocument);
}
示例2: UpdateDocument
public override void UpdateDocument(MongoCollection<BsonDocument> collection, BsonDocument document) {
if (document.Contains("MaxErrors"))
document.Remove("MaxErrors");
if (document.Contains("MaxErrorsPerStack"))
document.Remove("MaxErrorsPerStack");
collection.Save(document);
}
示例3: 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);
}
示例4: 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);
}
示例5: InsertAnimals
public static async void InsertAnimals(IMongoDatabase db)
{
//var client = new MongoClient();
//var db = client.GetDatabase("test");
var animals = db.GetCollection<BsonDocument>("animals");
var animal = new BsonDocument
{
{"animal", "monkey"}
};
try
{
await animals.InsertOneAsync(animal);
animal.Remove("animal");
animal.Add("animal", "cat");
await animals.InsertOneAsync(animal);
animal.Remove("animal");
animal.Add("animal", "lion");
await animals.InsertOneAsync(animal);
}
catch (Exception ex)
{
Console.WriteLine("ErroredOut", ex.Message.ToString());
}
var count = 0;
var filter = new BsonDocument();
using (var cursor = await animals.FindAsync(filter))
{
while (await cursor.MoveNextAsync())
{
var batch = cursor.Current;
foreach (var document in batch)
{
count++;
}
}
}
Console.WriteLine("Total Count {0}", count);
}
示例6: 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);
}
示例7: 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("MaxErrorsPerDay")) {
int maxErrorsPerDay = -1;
var maxErrorsPerDayElement = document.GetValue("MaxErrorsPerDay");
if (maxErrorsPerDayElement.IsInt32)
maxErrorsPerDay = maxErrorsPerDayElement.AsInt32;
else if (maxErrorsPerDayElement.IsInt64)
maxErrorsPerDay = (int)maxErrorsPerDayElement.AsInt64;
document.Set("MaxEventsPerMonth", maxErrorsPerDay > 0 ? maxErrorsPerDay * 30 : -1);
document.Remove("MaxErrorsPerDay");
}
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);
}
if (document.Contains("PlanId")) {
string planId = document.GetValue("PlanId").AsString;
var currentPlan = BillingManager.GetBillingPlan(planId);
document.Set("PlanName", currentPlan != null ? currentPlan.Name : planId);
document.Set("PlanDescription", currentPlan != null ? currentPlan.Description : planId);
}
collection.Save(document);
}
示例8: UpdateDocument
public override void UpdateDocument(MongoCollection<BsonDocument> collection, BsonDocument document) {
if (document.Contains("oid")) {
var organizationId = document.GetValue("oid").AsNullableObjectId;
if (!organizationId.HasValue || organizationId.Value == ObjectId.Empty) {
document.Remove("oid");
} else {
var organizationCollection = Database.GetCollection("organization");
var organization = organizationCollection.FindOneById(organizationId);
// The organization with this id could not be found.. Remove the webhook.
if (organization == null) {
collection.Remove(Query.EQ("_id", document.GetDocumentId()));
return;
}
}
}
var projectCollection = Database.GetCollection("project");
if (document.Contains("pid")) {
var projectId = document.GetValue("pid").AsNullableObjectId;
if (!projectId.HasValue || projectId.Value == ObjectId.Empty) {
document.Remove("pid");
} else {
var project = projectCollection.FindOneById(projectId);
// The project with this id could not be found.. Remove the webhook.
if (project == null) {
collection.Remove(Query.EQ("_id", document.GetDocumentId()));
return;
}
if (!document.Contains("oid"))
document.Set("oid", project.GetValue("oid").AsObjectId);
}
}
if (!document.Contains("oid") && !document.Contains("pid")) {
collection.Remove(Query.EQ("_id", document.GetDocumentId()));
return;
}
collection.Save(document);
}
示例9: CreateJsonFile
private static void CreateJsonFile(string jsonReportsDirectory, BsonDocument report)
{
report.Remove("_id");
BsonValue productIdAsBson;
report.TryGetValue("product-id", out productIdAsBson);
using (var file = new StreamWriter(jsonReportsDirectory + productIdAsBson.AsInt32 + ".json"))
{
file.WriteLine(report.ToJson());
}
}
示例10: Execute
public void Execute(BsonDocument doc)
{
var occurance = new BsonDocument(doc.GetElement("time"),
doc.GetElement("details"));
doc.Remove("time");
doc.Remove("details");
var query = Query.And(Query.EQ("token", doc["token"]),
Query.EQ("hash", doc["hash"]));
UpdateBuilder ub = new UpdateBuilder();
ub.Push("occurances", occurance);
ub.Set("token", doc["token"]);
ub.Set("hash", doc["hash"]);
ub.Set("level", doc["level"]);
ub.Set("common", doc["common"]);
ub.Set("lastTime", occurance["time"]);
Events.Update(query, ub, UpdateFlags.Upsert);
}
示例11: 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);
}
示例12: Change
public void Change(ObjectId id, BsonDocument changes)
{
var builder = Builders<BsonDocument>.Update;
var changeDefinitions = new List<UpdateDefinition<BsonDocument>>();
changes.Remove("_id");
changes.Elements.ToList().ForEach(element =>
{
changeDefinitions.Add(builder.Set(element.Name, element.Value));
});
Change(id, builder.Combine(changeDefinitions));
}
示例13: UpdateDocument
public override void UpdateDocument(MongoCollection<BsonDocument> collection, BsonDocument document) {
if (document.Contains("OrganizationId"))
document.ChangeName("OrganizationId", "oid");
if (document.Contains("ProjectId"))
document.ChangeName("ProjectId", "pid");
if (document.Contains("Version"))
document.Remove("Version");
document.Set("Version", "1.0.0.0");
collection.Save(document);
}
示例14: UpdateDocument
public override void UpdateDocument(MongoCollection<BsonDocument> collection, BsonDocument document) {
if (document.Contains("EmailNotificationsEnabled")) {
bool emailNotificationsEnabled = document.GetValue("EmailNotificationsEnabled").AsBoolean;
while (document.Contains("EmailNotificationsEnabled"))
document.Remove("EmailNotificationsEnabled");
document.Set("EmailNotificationsEnabled", emailNotificationsEnabled);
}
if (document.Contains("EmailAddress")) {
string emailAddress = document.GetValue("EmailAddress").AsString;
if (!String.IsNullOrWhiteSpace(emailAddress))
document.Set("EmailAddress", emailAddress.ToLowerInvariant().Trim());
}
collection.Save(document);
}
示例15: UpdateDocument
public override void UpdateDocument(MongoCollection<BsonDocument> collection, BsonDocument document) {
var errorRepository = new ErrorRepository(collection.Database, null, null, null);
BsonValue id = document.GetDocumentId();
if (id == null || !id.IsObjectId)
return;
Error error = errorRepository.GetById(id.ToString());
if (error == null)
return;
if (document.Contains("sig"))
document.Remove("sig");
var signatureFactory = new ErrorSignatureFactory();
// updates the document to set the IsSignatureTarget
ErrorSignature signature = signatureFactory.GetSignature(error);
errorRepository.Update(error);
}