本文整理汇总了C#中BsonDocument.GetElement方法的典型用法代码示例。如果您正苦于以下问题:C# BsonDocument.GetElement方法的具体用法?C# BsonDocument.GetElement怎么用?C# BsonDocument.GetElement使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BsonDocument
的用法示例。
在下文中一共展示了BsonDocument.GetElement方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetMatchDocument
/// <summary>
/// 获取Match
/// </summary>
/// <returns></returns>
public BsonDocument GetMatchDocument()
{
BsonDocument Matchlist = new BsonDocument();
foreach (ctlMatchItem item in this.Controls)
{
BsonDocument match = item.getMatchItem();
if (match != null)
{
string MatchName = match.GetElement(0).Name;
if (Matchlist.Contains(MatchName))
{
BsonDocument AddMatch = match.GetElement(0).Value.AsBsonDocument;
Matchlist.GetElement(MatchName).Value.AsBsonDocument.Add(AddMatch);
}
else {
Matchlist.Add(match);
}
}
}
if (Matchlist.ElementCount > 0)
{
return new BsonDocument("$match", Matchlist);
}
else
{
return null;
}
}
示例2: TestBsonDocumentNoId
public void TestBsonDocumentNoId()
{
_collection.RemoveAll();
var document = new BsonDocument
{
{ "A", 1 }
};
_collection.Save(document);
Assert.Equal(2, document.ElementCount);
Assert.Equal("_id", document.GetElement(0).Name);
Assert.IsType<BsonObjectId>(document["_id"]);
Assert.NotEqual(ObjectId.Empty, document["_id"].AsObjectId);
Assert.Equal(1, _collection.Count());
var id = document["_id"].AsObjectId;
document["A"] = 2;
_collection.Save(document);
Assert.Equal(id, document["_id"].AsObjectId);
Assert.Equal(1, _collection.Count());
document = _collection.FindOneAs<BsonDocument>();
Assert.Equal(2, document.ElementCount);
Assert.Equal(id, document["_id"].AsObjectId);
Assert.Equal(2, document["A"].AsInt32);
}
示例3: TestBsonDocumentBsonNullId
public void TestBsonDocumentBsonNullId()
{
collection.RemoveAll();
var document = new BsonDocument {
{ "_id", BsonNull.Value },
{ "A", 1 }
};
collection.Save(document);
Assert.AreEqual(2, document.ElementCount);
Assert.AreEqual("_id", document.GetElement(0).Name);
Assert.IsInstanceOf<BsonObjectId>(document["_id"]);
Assert.AreNotEqual(ObjectId.Empty, document["_id"].AsObjectId);
Assert.AreEqual(1, collection.Count());
var id = document["_id"].AsObjectId;
document["A"] = 2;
collection.Save(document);
Assert.AreEqual(id, document["_id"].AsObjectId);
Assert.AreEqual(1, collection.Count());
document = collection.FindOneAs<BsonDocument>();
Assert.AreEqual(2, document.ElementCount);
Assert.AreEqual(id, document["_id"].AsObjectId);
Assert.AreEqual(2, document["A"].AsInt32);
}
示例4: UpdateDocument
public override void UpdateDocument(MongoCollection<BsonDocument> collection, BsonDocument document) {
string id = document.GetElement(MonthStackStatsRepository.FieldNames.Id).Value.AsString;
string[] parts = id.Split('/');
if (parts.Length > 0)
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(MonthStackStatsRepository.FieldNames.ProjectId, projectId);
}
document.Set(MonthStackStatsRepository.FieldNames.ErrorStackId, new BsonObjectId(new ObjectId(errorStackId)));
var emptyBlocks = new List<BsonElement>();
BsonDocument dayBlocks = document.GetValue(MonthStackStatsRepository.FieldNames.DayStats).AsBsonDocument;
foreach (BsonElement b in dayBlocks.Elements) {
if (b.Value.AsInt32 == 0)
emptyBlocks.Add(b);
}
foreach (BsonElement b in emptyBlocks)
dayBlocks.RemoveElement(b);
collection.Save(document);
}
示例5: GetMatchDocument
/// <summary>
/// 获取Match
/// </summary>
/// <returns></returns>
public BsonDocument GetMatchDocument()
{
var matchlist = new BsonDocument();
foreach (Control item in Controls)
{
if (item.GetType().FullName == typeof(Button).FullName) continue;
var match = ((CtlMatchItem)item).GetMatchItem();
if (match != null)
{
var matchName = match.GetElement(0).Name;
if (matchlist.Contains(matchName))
{
var addMatch = match.GetElement(0).Value.AsBsonDocument;
matchlist.GetElement(matchName).Value.AsBsonDocument.AddRange(addMatch);
}
else
{
matchlist.AddRange(match);
}
}
}
if (matchlist.ElementCount > 0)
{
return new BsonDocument("$match", matchlist);
}
return null;
}
示例6: GetMatchDocument
/// <summary>
/// 获取Match
/// </summary>
/// <returns></returns>
public BsonDocument GetMatchDocument()
{
var matchlist = new BsonDocument();
foreach (CtlMatchItem item in Controls)
{
var match = item.GetMatchItem();
if (match != null)
{
var matchName = match.GetElement(0).Name;
if (matchlist.Contains(matchName))
{
var addMatch = match.GetElement(0).Value.AsBsonDocument;
matchlist.GetElement(matchName).Value.AsBsonDocument.AddRange(addMatch);
}
else
{
matchlist.AddRange(match);
}
}
}
if (matchlist.ElementCount > 0)
{
return new BsonDocument("$match", matchlist);
}
return null;
}
示例7: DefaultImplementation
// public static methods
/// <summary>
/// Default implementation of the CanCommandBeSentToSecondary delegate.
/// </summary>
/// <param name="document">The command.</param>
/// <returns>True if the command can be sent to a secondary member of a replica set.</returns>
public static bool DefaultImplementation(BsonDocument document)
{
if (document.ElementCount == 0)
{
return false;
}
var commandName = document.GetElement(0).Name;
if (__secondaryOkCommands.Contains(commandName))
{
return true;
}
if (commandName.Equals("mapreduce", StringComparison.InvariantCultureIgnoreCase))
{
BsonValue outValue;
if (document.TryGetValue("out", out outValue) && outValue.IsBsonDocument)
{
return outValue.AsBsonDocument.Contains("inline");
}
}
return false;
}
示例8: TestBsonDocumentEmptyGuid
public void TestBsonDocumentEmptyGuid()
{
_collection.RemoveAll();
var document = new BsonDocument
{
{ "_id", Guid.Empty },
{ "A", 1 }
};
_collection.Save(document);
Assert.AreEqual(2, document.ElementCount);
Assert.AreEqual("_id", document.GetElement(0).Name);
Assert.IsInstanceOf<BsonBinaryData>(document["_id"]);
Assert.AreNotEqual(Guid.Empty, document["_id"].AsGuid);
Assert.AreEqual(1, _collection.Count());
var id = document["_id"].AsGuid;
document["A"] = 2;
_collection.Save(document);
Assert.AreEqual(id, document["_id"].AsGuid);
Assert.AreEqual(1, _collection.Count());
document = _collection.FindOneAs<BsonDocument>();
Assert.AreEqual(2, document.ElementCount);
Assert.AreEqual(id, document["_id"].AsGuid);
Assert.AreEqual(2, document["A"].AsInt32);
}
示例9: applyUpdateCommands
public static void applyUpdateCommands(BsonDocument doc, BsonDocument change_spec)
{
foreach (var field in change_spec) {
if (field.Name.Length > 0 && field.Name[0] == '$') {
// update command
switch (field.Name) {
case "$set":
_applySet(doc, field.Value.AsBsonDocument);
break;
case "$inc":
_applyInc(doc, field.Value.AsBsonDocument);
break;
case "$unset":
_applyUnset(doc, field.Value.AsBsonDocument);
break;
case "$push":
case "$pushAll":
case "$addToSet":
case "$pop":
case "$pull":
case "$pullAll":
case "$rename":
case "$":
throw new Exception("unimplemented update operator: " + field.Name);
default:
throw new Exception("unknown update operator: " + field.Name);
}
} else {
// field replace
if (field.Value.BsonType == BsonType.Document) {
if (!doc.Contains(field.Name) ||
doc.GetElement(field.Name).Value.BsonType != BsonType.Document) {
// make a document to hold the recurse
doc.Set(field.Name, new BsonDocument());
}
// recursively apply changes
applyUpdateCommands(doc.GetElement(field.Name).Value.AsBsonDocument,
field.Value.AsBsonDocument);
} else {
// otherwise just apply the change directly
doc.Set(field.Name, field.Value);
}
}
}
}
示例10: 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);
}
示例11: 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);
}
示例12: 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);
}
示例13: UpdateDocument
public override void UpdateDocument(MongoCollection<BsonDocument> collection, BsonDocument document) {
if (!document.Contains(ErrorRepository.FieldNames.ExceptionlessClientInfo))
return;
BsonDocument clientInfo = document.GetElement(ErrorRepository.FieldNames.ExceptionlessClientInfo).Value.AsBsonDocument;
if (clientInfo.Contains("SubmissionMethod"))
clientInfo.ChangeName("SubmissionMethod", ErrorRepository.FieldNames.SubmissionMethod);
if (clientInfo.Contains(ErrorRepository.FieldNames.InstallDate)) {
BsonValue installDateValue = clientInfo.GetElement(ErrorRepository.FieldNames.InstallDate).Value;
if (installDateValue.IsBsonArray)
return;
DateTime installDate = installDateValue.ToUniversalTime();
clientInfo.AsBsonDocument.Set(ErrorRepository.FieldNames.InstallDate, new BsonArray(new BsonValue[] { new BsonInt64(installDate.Ticks), new BsonInt32(-360) }));
}
collection.Save(document);
}
示例14: TestSetElementReplaceElement
public void TestSetElementReplaceElement()
{
var document = new BsonDocument("x", 1);
var element = new BsonElement("x", 2);
document.SetElement(element);
Assert.AreEqual(1, document.ElementCount);
Assert.AreEqual("x", document.GetElement(0).Name);
Assert.AreEqual(2, document["x"].AsInt32);
}
示例15: TestSetDocumentIdNewElement
public void TestSetDocumentIdNewElement()
{
var document = new BsonDocument("x", 1);
((IBsonIdProvider)BsonDocumentSerializer.Instance).SetDocumentId(document, BsonValue.Create(2));
Assert.AreEqual(2, document.ElementCount);
Assert.AreEqual("_id", document.GetElement(0).Name);
Assert.AreEqual(2, document["_id"].AsInt32);
}