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


C# IMongoCollection.DeleteOneAsync方法代码示例

本文整理汇总了C#中IMongoCollection.DeleteOneAsync方法的典型用法代码示例。如果您正苦于以下问题:C# IMongoCollection.DeleteOneAsync方法的具体用法?C# IMongoCollection.DeleteOneAsync怎么用?C# IMongoCollection.DeleteOneAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IMongoCollection的用法示例。


在下文中一共展示了IMongoCollection.DeleteOneAsync方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: DeleteAsync

        public static async Task<int> DeleteAsync(IMongoCollection<BsonDocument> collection, params object[] keyValues)
        {
            if (keyValues.Length == 0)
                throw new ArgumentException("At least 1 keyValue required.");

            if (keyValues.Length == 1)
            {
                var ret = await collection.DeleteOneAsync(Builders<BsonDocument>.Filter.Eq("_id", keyValues[0]));
                return ret != null ? (int)ret.DeletedCount : 0;
            }
            else
            {
                var keyPath = ToDotPath(keyValues.Skip(1));
                var ret = await collection.UpdateOneAsync(Builders<BsonDocument>.Filter.Eq("_id", keyValues[0]),
                                                          Builders<BsonDocument>.Update.Unset(keyPath));
                return ret != null ? (int)ret.ModifiedCount : 0;
            }
        }
开发者ID:cupsster,项目名称:TrackableData,代码行数:18,代码来源:DocumentHelper.cs

示例2: ExecuteAsync

 public async Task ExecuteAsync(DeleteClimbCommandParameters parameters, IMongoCollection<Climb> collection)
 {
     var filter = Builders<Climb>.Filter.Eq(c => c.Id == parameters.Id, true);
     await collection.DeleteOneAsync(filter);
 }
开发者ID:MikeBeastall,项目名称:MonkeyStrong,代码行数:5,代码来源:DeleteClimbCommand.cs

示例3: Dr

        private static async Task Dr(IMongoCollection<BsonDocument> leaders, BsonDocument filter, IMongoCollection<BsonDocument> users, IMongoCollection<BsonDocument> leadersbak)
        {
            using (var cursor = await leaders.FindAsync(filter))
            {

                while (await cursor.MoveNextAsync())
                {
                    var batch = cursor.Current;
                    foreach (var rt in batch)
                    {
                        BsonArray bRetweeters = rt["retweeters_id"].AsBsonArray;

                        //if (bRetweeters.Count == 0)
                        //    continue;

                        foreach (var bUser in bRetweeters)
                        {
                            var lUser = bUser.ToInt64();
                            try
                            {

                                log.Info("readling retweeter {0}", lUser);
                                var usersFilter = Builders<BsonDocument>.Filter.Eq("id", lUser);
                                var result = await users.Find(usersFilter).ToListAsync();
                                if (result.Count > 0)
                                    continue;

                                log.Info("downloading retweeter {0}", lUser);
                                TwitterProfileHandler profileHandler = new TwitterProfileHandlerMongo();
                                string screenName = profileHandler.Download(lUser);
                                //TwitterHomelineHandler homeHandler = new TwitterHomelineHandlerMongo();
                                //homeHandler.Download(screenName);
                            }
                            catch (Exception ex)
                            {
                                string msg = "Error trying to download profile for user:{0}";
                                msg = string.Format(msg, lUser);
                                log.Error(ex, msg);
                            }
                        }

                        //rt["done"] = true;
                        //var filterupdate = Builders<BsonDocument>.Filter.Eq("_id", rt["_id"]);
                        //var update = Builders<BsonDocument>.Update.Push("done", true);
                        //await leaders.UpdateOneAsync(filterupdate, rt);
                        await leadersbak.InsertOneAsync(rt);
                        var filterbak = Builders<BsonDocument>.Filter.Eq("_id", rt["_id"]);
                        await leaders.DeleteOneAsync(filterbak);
                    }
                }
            }

            Thread.Sleep(5000);
        }
开发者ID:johnnytorres,项目名称:twitterlc,代码行数:54,代码来源:Program.cs

示例4: 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, score:-1}")
                .ToCursorAsync())
            {
                int i = 1;
                using (StreamWriter w = File.AppendText("c:\\data\\test2.txt"))
                {
                    while (await cursor.MoveNextAsync())  //iterate over each batch
                    {
                        foreach (var doc in cursor.Current)
                        {
                            string text = i + " :=> sid: " + doc.student_id + ":" + doc.score;
                            Console.WriteLine(text);
                            w.WriteLine(text);
                            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,代码行数:31,代码来源:Program2.cs


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