本文整理汇总了C#中BsonDocument.Merge方法的典型用法代码示例。如果您正苦于以下问题:C# BsonDocument.Merge方法的具体用法?C# BsonDocument.Merge怎么用?C# BsonDocument.Merge使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BsonDocument
的用法示例。
在下文中一共展示了BsonDocument.Merge方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestMerge
public void TestMerge() {
var document = new BsonDocument();
document.Merge(new BsonDocument("x", 1));
Assert.AreEqual(1, document["x"].AsInt32);
document.Merge(new BsonDocument("x", 2)); // don't overwriteExistingElements
Assert.AreEqual(1, document["x"].AsInt32); // has old value
document.Merge(new BsonDocument("x", 2), true); // overwriteExistingElements
Assert.AreEqual(2, document["x"].AsInt32); // has new value
}
示例2: CreateIndexDocument
// methods
internal BsonDocument CreateIndexDocument(SemanticVersion serverVersion)
{
Feature.Collation.ThrowIfNotSupported(serverVersion, _collation);
var document = new BsonDocument
{
{ "key", _keys },
{ "name", GetIndexName() },
{ "background", () => _background.Value, _background.HasValue },
{ "bits", () => _bits.Value, _bits.HasValue },
{ "bucketSize", () => _bucketSize.Value, _bucketSize.HasValue },
{ "collation", () => _collation.ToBsonDocument(), _collation != null },
{ "default_language", () => _defaultLanguage, _defaultLanguage != null },
{ "expireAfterSeconds", () => _expireAfter.Value.TotalSeconds, _expireAfter.HasValue },
{ "language_override", () => _languageOverride, _languageOverride != null },
{ "max", () => _max.Value, _max.HasValue },
{ "min", () => _min.Value, _min.HasValue },
{ "partialFilterExpression", _partialFilterExpression, _partialFilterExpression != null },
{ "sparse", () => _sparse.Value, _sparse.HasValue },
{ "2dsphereIndexVersion", () => _sphereIndexVersion.Value, _sphereIndexVersion.HasValue },
{ "storageEngine", () => _storageEngine, _storageEngine != null },
{ "textIndexVersion", () => _textIndexVersion.Value, _textIndexVersion.HasValue },
{ "unique", () => _unique.Value, _unique.HasValue },
{ "v", () => _version.Value, _version.HasValue },
{ "weights", () => _weights, _weights != null }
};
if (_additionalOptions != null)
{
document.Merge(_additionalOptions, overwriteExistingElements: false);
}
return document;
}
示例3: MassageReply
private BsonDocument MassageReply(string commandName, BsonDocument reply, BsonDocument expectedReply)
{
var massagedReply = (BsonDocument)DeepCopy(reply);
switch (commandName)
{
case "find":
case "getMore":
if (massagedReply.Contains("cursor") && massagedReply["cursor"]["id"] != 0L)
{
massagedReply["cursor"]["id"] = 42L;
}
break;
case "killCursors":
massagedReply["cursorsUnknown"][0] = 42L;
break;
case "delete":
case "insert":
case "update":
if (massagedReply.Contains("writeErrors"))
{
foreach (BsonDocument writeError in (BsonArray)massagedReply["writeErrors"])
{
writeError["code"] = 42;
writeError["errmsg"] = "";
}
}
break;
}
// add any fields in the actual reply into the expected reply that don't already exist
expectedReply.Merge(reply, false);
return massagedReply;
}
示例4: ProcessQueryReplyMessage
private void ProcessQueryReplyMessage(CommandState state, ReplyMessage<RawBsonDocument> replyMessage, ConnectionId connectionId)
{
if (_succeededEvent != null)
{
BsonDocument reply;
if (state.CommandName == "explain")
{
reply = new BsonDocument("ok", 1);
reply.Merge(replyMessage.Documents[0]);
}
else
{
var batchName = state.CommandName == "find" ? "firstBatch" : "nextBatch";
reply = new BsonDocument
{
{ "cursor", new BsonDocument
{
{ "id", replyMessage.CursorId },
{ "ns", state.QueryNamespace.FullName },
{ batchName, new BsonArray(replyMessage.Documents) }
}},
{ "ok", 1 }
};
}
_succeededEvent(new CommandSucceededEvent(
state.CommandName,
reply,
state.OperationId,
replyMessage.ResponseTo,
connectionId,
state.Stopwatch.Elapsed));
}
}
示例5: TestMergeNull
public void TestMergeNull()
{
var document = new BsonDocument();
Assert.Throws<ArgumentNullException>(() => { document.Merge(null); });
}
示例6: ToWriteConcernResult
// private methods
private WriteConcernResult ToWriteConcernResult(BulkWriteResult bulkWriteResult, BulkWriteException bulkWriteException)
{
if (!bulkWriteResult.IsAcknowledged)
{
return null;
}
// don't include InsertedCount in getLastErrorResponse
var documentsAffectedCount =
bulkWriteResult.DeletedCount +
bulkWriteResult.MatchedCount +
bulkWriteResult.Upserts.Count;
var isUpdate = bulkWriteResult.ProcessedRequests.Any(r => r.RequestType == WriteRequestType.Update);
var updatedExisting = false;
BulkWriteUpsert upsert = null;
if (isUpdate)
{
upsert = bulkWriteResult.Upserts.LastOrDefault();
updatedExisting = documentsAffectedCount > 0 && upsert == null;
}
var code = 0;
string message = null;
BsonDocument details = null;
if (bulkWriteException != null)
{
var lastWriteError = bulkWriteException.WriteErrors.LastOrDefault();
var writeConcernError = bulkWriteException.WriteConcernError;
code = 8; // UnknownError
if (lastWriteError != null)
{
code = lastWriteError.Code;
message = lastWriteError.Message;
details = lastWriteError.Details;
}
else if (writeConcernError != null)
{
code = writeConcernError.Code;
message = writeConcernError.Message;
details = writeConcernError.Details;
}
}
var getLastErrorResponse = new BsonDocument
{
{ "ok", 1 },
{ "code", code, code != 0 },
{ "err", message, message != null },
{ "n", documentsAffectedCount },
{ "updatedExisting", updatedExisting, isUpdate },
{ "upserted", () => upsert.Id, isUpdate && upsert != null },
};
getLastErrorResponse.Merge(details, false); // don't overwrite existing elements
return new WriteConcernResult(getLastErrorResponse);
}
示例7: CreateSubject
private GridFSFileInfo CreateSubject(
IEnumerable<string> aliases = null,
int? chunkSizeBytes = null,
string contentType = null,
BsonDocument extraElements = null,
string filename = null,
BsonValue idAsBsonValue = null,
long? length = null,
string md5 = null,
BsonDocument metadata = null,
DateTime? uploadDateTime = null)
{
var backingDocument = new BsonDocument
{
{ "_id", idAsBsonValue ?? (BsonValue)ObjectId.GenerateNewId() },
{ "length", length ?? 0 },
{ "chunkSize", chunkSizeBytes ?? 255 * 1024 },
{ "uploadDate", uploadDateTime ?? DateTime.UtcNow },
{ "md5", md5 ?? "md5" },
{ "filename", filename ?? "filename" },
{ "contentType", contentType, contentType != null },
{ "aliases", () => new BsonArray(aliases.Select(a => new BsonString(a))), aliases != null },
{ "metadata", metadata, metadata != null }
};
if (extraElements != null)
{
backingDocument.Merge(extraElements, overwriteExistingElements: false);
}
return new GridFSFileInfo(backingDocument);
}