本文整理汇总了C#中IMongoCollection.ReplaceOneAsync方法的典型用法代码示例。如果您正苦于以下问题:C# IMongoCollection.ReplaceOneAsync方法的具体用法?C# IMongoCollection.ReplaceOneAsync怎么用?C# IMongoCollection.ReplaceOneAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IMongoCollection
的用法示例。
在下文中一共展示了IMongoCollection.ReplaceOneAsync方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: doReplace
static void doReplace(IMongoCollection<Person> collection)
{
var builder = Builders<Person>.Filter;
FilterDefinition<Person> searchFilter = builder.And(builder.Eq("Age", 50));
Person p2 = new Person("jones");
p2.Age = 100;
var replaceResult = collection.ReplaceOneAsync(searchFilter, p2);
}
示例2: Upsert
private static void Upsert(IMongoCollection<BsonDocument> collection, BsonDocument newDoc, FilterDefinition<BsonDocument> filter)
{
var options = new UpdateOptions();
options.IsUpsert = true;
collection.ReplaceOneAsync(filter, newDoc, options).Wait();
}
示例3: findDocuments
static async Task findDocuments(IMongoCollection<student> collection, FilterDefinition<student> searchFilter)
{
//Option 1: for iterting over many documents on the server.
Console.WriteLine("--------------------------------------------------------------------");
///using (var cursor = await collection.Find(searchFilter).Sort("{student_id:1, scores.type:1}").ToCursorAsync())
using (var cursor = await collection.Find(searchFilter).ToCursorAsync())
{
using (StreamWriter w = File.AppendText("c:\\data\\hw31.txt"))
{
while (await cursor.MoveNextAsync()) //iterate over each batch
{
foreach (var doc in cursor.Current)
{
double minHWScore = 100.0;
///string text = i + " :=> sid: " + doc.student_id + ":" + doc.scores.ToString();
List<studentscore> thisStudentScores = doc.scores.ToList();
foreach (studentscore s in thisStudentScores)
{
if (s.type.Equals("homework"))
{
if (s.score < minHWScore)
{
minHWScore = s.score;
}
}
}
studentscore[] newScores = thisStudentScores.Where((x) => x.score != minHWScore).ToArray<studentscore>();
doc.scores = newScores.ToArray<studentscore>();
var filter = Builders<student>.Filter.Eq("Id", doc.Id);
await collection.ReplaceOneAsync(filter, doc);
Console.WriteLine(doc.ToString());
w.WriteLine(doc.ToString());
/**
if (i % 4 == 0)
{
Console.WriteLine("lowest score for " + doc.student_id + " is " + doc.score);
w.WriteLine("lowest score for " + doc.student_id + " is " + doc.score);
await collection.DeleteOneAsync(a => a.Id == doc.Id);
}
i++;
**/
}
}
}
}
}
示例4: InsertRandomDocumentsIntoDatabase
static async Task InsertRandomDocumentsIntoDatabase(WikimediaClient client, IMongoCollection<BsonDocument> collection)
{
var response = await client.GetMaxRandomArticles();
var updates = response.Pages.Values.Select(page => {
var doc = DocumentFromPage(page);
return collection.ReplaceOneAsync(
Builders<BsonDocument>.Filter.Eq(d => d["PageId"], page.PageId), doc,
new UpdateOptions { IsUpsert = true });
});
await Task.WhenAll(updates);
}
示例5: ProcessLineageSpecificity
private static async Task ProcessLineageSpecificity(IMongoCollection<EncodeTbfsPeak> tbfsCollection,
string chromosome, string cell, List<EncodeTbfsPeak> tbfs, List<string> allowedCells, int cellCount)
{
Console.WriteLine("Processing " + chromosome + "-" + cell + "...");
var currentSet = new List<EncodeTbfsPeak>();
foreach (var peak in tbfs.OrderBy(x=> x.StartPos))
{
//Current window start
var currentPos = peak.StartPos;
//Check if any peaks have fallen out of range
foreach (var cPeak in currentSet)
{
//Do peak completion
if (cPeak.EndPos < currentPos)
{
if (cPeak.CellOverlapCount == 1)
{
cPeak.Class = "cell-specific";
}
else if (cPeak.CellOverlapCount == cellCount)
{
cPeak.Class = "ubiquitous";
}
}
else
{
cPeak.Class = "common";
}
await tbfsCollection.ReplaceOneAsync(x => x.Id == cPeak.Id, cPeak);
}
currentSet.Add(peak);
}
/* var totalCount = tbfs.Count;
for (var i = 0; i < totalCount; i++)
{
var peak = tbfs[i];
if (peak.Cell == cell)
{
var overlappedCells = "";
var overlapCount = 0;
for (var j = 0; j < totalCount; j++)
{
var compPeak = tbfs[j];
//Don't bother comparing if we have that cell type already
if (!overlappedCells.Contains(compPeak.Cell))
{
//Check for overlap
if (compPeak.StartPos <= peak.EndPos && compPeak.EndPos >= peak.StartPos)
{
overlappedCells += compPeak.Cell + ":";
overlapCount++;
}
}
}
peak.CellOverlapCount = overlapCount;
if (overlapCount == 1)
{
peak.Class = "cell-specific";
}
else if (overlapCount == cellCount)
{
peak.Class = "ubiquitous";
}
// else if (overlapCount == cellCount - 1)
// {
// var listedCells = groupBy.Select(x => x.Key).ToList();
// var missingCell = allowedCells.Except(listedCells).ToList();
// peak.MissingCell = missingCell[0];
// peak.Class = "common";
// }
else
{
peak.Class = "common";
}
await tbfsCollection.ReplaceOneAsync(x => x.Id == peak.Id, peak);
}
}*/
/*foreach (var peak in tbfs.Where(x => x.Cell == cell))
{
var overlap = tbfs.Where(x => x.StartPos <= peak.EndPos && x.EndPos >= peak.StartPos);
var groupBy = overlap.GroupBy(x => x.Cell);
var trueCount = groupBy.Count();
//.........这里部分代码省略.........