本文整理匯總了C#中BsonDocument.Take方法的典型用法代碼示例。如果您正苦於以下問題:C# BsonDocument.Take方法的具體用法?C# BsonDocument.Take怎麽用?C# BsonDocument.Take使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類BsonDocument
的用法示例。
在下文中一共展示了BsonDocument.Take方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: TestBatchSplittingBySizeWithErrorsOrdered
public void TestBatchSplittingBySizeWithErrorsOrdered()
{
_collection.Drop();
var documents = new BsonDocument[8];
for (var i = 0; i < 6; i++)
{
documents[i] = new BsonDocument { { "_id", i }, { "a", new string('x', 4 * 1024 * 1024) } };
}
documents[6] = new BsonDocument("_id", 0); // will fail
documents[7] = new BsonDocument("_id", 100);
var bulk = _collection.InitializeOrderedBulkOperation();
for (var i = 0; i < 8; i++)
{
bulk.Insert(documents[i]);
}
var exception = Assert.Throws<BulkWriteException>(() => { bulk.Execute(); });
var result = exception.Result;
Assert.IsNull(exception.WriteConcernError);
Assert.AreEqual(1, exception.WriteErrors.Count);
var writeError = exception.WriteErrors[0];
Assert.AreEqual(6, writeError.Index);
Assert.AreEqual(11000, writeError.Code);
var expectedResult = new ExpectedResult
{
InsertedCount = 6,
ProcessedRequestsCount = 7,
RequestCount = 8
};
CheckExpectedResult(expectedResult, result);
var expectedDocuments = documents.Take(6);
Assert.That(_collection.FindAll(), Is.EqualTo(expectedDocuments));
}