当前位置: 首页>>代码示例>>C#>>正文


C# IMongoCollection.ReplaceOneAsync方法代码示例

本文整理汇总了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);
 }
开发者ID:ax2015,项目名称:testprojects,代码行数:8,代码来源:Program.cs

示例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();
        }
开发者ID:johndarv,项目名称:MukMafiaTool,代码行数:7,代码来源:MongoRepository.cs

示例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++;
                            **/
                        }
                    }
                }
            }
        }
开发者ID:ax2015,项目名称:testprojects,代码行数:50,代码来源:hw31.cs

示例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);
 }
开发者ID:Grouptree,项目名称:wikipedia-downloader,代码行数:11,代码来源:Program.cs

示例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();

//.........这里部分代码省略.........
开发者ID:chris-cheshire,项目名称:genomics.tools,代码行数:101,代码来源:Program.cs


注:本文中的IMongoCollection.ReplaceOneAsync方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。