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


C# MongoCollection.Remove方法代码示例

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


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

示例1: DropDocument

 /// <summary>
 ///     删除单条数据
 /// </summary>
 /// <param name="mongoCol">表对象</param>
 /// <param name="objectId">ObjectId</param>
 /// <returns></returns>
 public static string DropDocument(MongoCollection mongoCol, string objectId)
 {
     CommandResult result;
     try
     {
         //有时候在序列化的过程中,objectId是由某个字段带上[id]特性客串的,所以无法转换为ObjectId对象
         //这里先尝试转换,如果可以转换,则转换
         ObjectId seekId;
         if (ObjectId.TryParse(objectId, out seekId))
         {
             //如果可以转换,则转换
             result =
                 new CommandResult(
                     mongoCol.Remove(Query.EQ(ConstMgr.KeyId, seekId), WriteConcern.Acknowledged)
                         .Response);
         }
         else
         {
             //不能转换则保持原状
             result =
                 new CommandResult(
                     mongoCol.Remove(Query.EQ(ConstMgr.KeyId, objectId), WriteConcern.Acknowledged)
                         .Response);
         }
     }
     catch (MongoCommandException ex)
     {
         result = new CommandResult(ex.Result);
     }
     BsonElement err;
     return !result.Response.TryGetElement("err", out err) ? string.Empty : err.ToString();
 }
开发者ID:magicdict,项目名称:MongoCola,代码行数:38,代码来源:Document.cs

示例2: Delete

 private static void Delete(MongoCollection<Log> logs)
 {
     var findOldLogsQuery = Query.And(Query.LT("LogDate", DateTime.Now.AddDays(-1)));
     logs.Remove(findOldLogsQuery);
     Console.WriteLine("DELETE");
     logs.FindAll().Print();
 }
开发者ID:MarKamenov,项目名称:TelerikAcademy,代码行数:7,代码来源:MongoCRUD.cs

示例3: UpdateDocument

        public override void UpdateDocument(MongoCollection<BsonDocument> collection, BsonDocument document) {
            if (document.Contains("oid")) {
                var organizationId = document.GetValue("oid").AsNullableObjectId;
                if (!organizationId.HasValue || organizationId.Value == ObjectId.Empty) {
                    document.Remove("oid");
                } else {
                    var organizationCollection = Database.GetCollection("organization");
                    var organization = organizationCollection.FindOneById(organizationId);

                    // The organization with this id could not be found.. Remove the webhook.
                    if (organization == null) {
                        collection.Remove(Query.EQ("_id", document.GetDocumentId()));
                        return;
                    }
                }
            }

            var projectCollection = Database.GetCollection("project");
            if (document.Contains("pid")) {
                var projectId = document.GetValue("pid").AsNullableObjectId;
                if (!projectId.HasValue || projectId.Value == ObjectId.Empty) {
                    document.Remove("pid");
                } else {
                    var project = projectCollection.FindOneById(projectId);

                    // The project with this id could not be found.. Remove the webhook.
                    if (project == null) {
                        collection.Remove(Query.EQ("_id", document.GetDocumentId()));
                        return;
                    }

                    if (!document.Contains("oid"))
                        document.Set("oid", project.GetValue("oid").AsObjectId);
                }
            }

            if (!document.Contains("oid") && !document.Contains("pid")) {
                collection.Remove(Query.EQ("_id", document.GetDocumentId()));
                return;
            }

            collection.Save(document);
        }
开发者ID:aamarber,项目名称:Exceptionless,代码行数:43,代码来源:v1.0.37.cs

示例4: UpdateDocument

        public override void UpdateDocument(MongoCollection<BsonDocument> collection, BsonDocument document) {
            if (document.Contains("oid")) {
                var organizationId = document.GetValue("oid").AsNullableObjectId;
                if (!organizationId.HasValue || organizationId.Value == ObjectId.Empty) {
                    // The organization id is invalid. Remove the token.
                    collection.Remove(Query.EQ("_id", document.GetDocumentId()));
                    return;
                }

                var organizationCollection = Database.GetCollection("organization");
                var organization = organizationCollection.FindOneById(organizationId.Value);

                // The organization with this id could not be found.. Remove the token.
                if (organization == null) {
                    collection.Remove(Query.EQ("_id", document.GetDocumentId()));
                    return;
                }
            }

            if (document.Contains("pid")) {
                var projectId = document.GetValue("pid").AsNullableObjectId;
                if (!projectId.HasValue || projectId.Value == ObjectId.Empty) {
                    // The project id is invalid. Remove the token.
                    collection.Remove(Query.EQ("_id", document.GetDocumentId()));
                    return;
                }

                var projectCollection = Database.GetCollection("project");
                var project = projectCollection.FindOneById(projectId.Value);

                // The project with this id could not be found.. Remove the token.
                if (project == null) {
                    collection.Remove(Query.EQ("_id", document.GetDocumentId()));
                    return;
                }
            }

            // Remove the token if it's not associated to an organization, project or user.
            if (!document.Contains("oid") && !document.Contains("pid") && !document.Contains("uid")) {
                collection.Remove(Query.EQ("_id", document.GetDocumentId()));
            }
        }
开发者ID:aamarber,项目名称:Exceptionless,代码行数:42,代码来源:v1.0.38.cs

示例5: DeleteGift

 public bool DeleteGift(Guid id)
 {
     if (mongoServer != null && giftedDB != null)
     {
         giftCollection = giftedDB.GetCollection<Gift>("Gift");
         IMongoQuery query = Query.EQ("_id", id);
         SafeModeResult result = giftCollection.Remove(query);
         return result.DocumentsAffected == 1;
     }
     else
         return false;
 }
开发者ID:VishalRJoshi,项目名称:Gifted,代码行数:12,代码来源:MongoDataAccess.cs

示例6: RemoveWords

 public static void RemoveWords(MongoCollection words)
 {
     Console.Write("Enter word for remove: ");
     string editWord = Console.ReadLine().ToLower();
     var searched = words.AsQueryable<Word>().FirstOrDefault(w => w.Value == editWord);
     if (searched != null)
     {
         var query = Query.EQ("_id", searched.Id);
         words.Remove(query);
     }
     else
     {
         Console.WriteLine("This word is not exist");
     }
 }
开发者ID:Gerya,项目名称:TelerikAcademy,代码行数:15,代码来源:Utilities.cs

示例7: DeleteAllDocumentsFromCollection

        /// <summary>
        /// Demo deleting documents from collection.
        /// </summary>
        /// <param name="orders">The orders.</param>
        static void DeleteAllDocumentsFromCollection( MongoCollection< Order > collection )
        {
            Console.WriteLine( "\n\n======= Delete Documents =======" );
            Console.WriteLine( string.Format( "Document Count Before Delete: [ {0} ]", collection.Count() ) );

            // Delete documents matching a criteria.
            collection.Remove( new {CustomerName = "Elmer Fudd"} );
            Console.WriteLine( string.Format( "Document Count After Deleting Elmer Fudd: [ {0} ]", collection.Count() ) );

            // Delete all docs.
            collection.Remove( new {} );

            Console.WriteLine( "Deleted all docs" );
            Console.WriteLine( string.Format( "Document Count After Deleting All Docs: [ {0} ]", collection.Count() ) );
        }
开发者ID:ChrisEdwards,项目名称:IntroducingMongoDB,代码行数:19,代码来源:Program.cs

示例8: Remove

 protected bool Remove(MongoCollection<object> collection, Guid id)
 {
     return collection.Remove(Query.EQ("_id", id), WriteConcern.Acknowledged).Ok;
 }
开发者ID:pitlabcloud,项目名称:activity-cloud,代码行数:4,代码来源:BaseRegistry.cs

示例9: DropJsDocument

 /// <summary>
 ///     删除js数据
 /// </summary>
 /// <param name="mongoCol"></param>
 /// <param name="strKey"></param>
 /// <returns></returns>
 public static string DropJsDocument(MongoCollection mongoCol, object strKey)
 {
     var result = new CommandResult(new BsonDocument());
     if (QueryHelper.IsExistByKey(strKey.ToString()))
     {
         try
         {
             result =
                 new CommandResult(
                     mongoCol.Remove(Query.EQ(ConstMgr.KeyId, (BsonValue) strKey), WriteConcern.Acknowledged)
                         .Response);
         }
         catch (MongoCommandException ex)
         {
             result = new CommandResult(ex.Result);
         }
     }
     BsonElement err;
     return !result.Response.TryGetElement("err", out err) ? string.Empty : err.ToString();
 }
开发者ID:magicdict,项目名称:MongoCola,代码行数:26,代码来源:Document.cs

示例10: DropDocument

 /// <summary>
 /// 删除数据
 /// </summary>
 /// <param name="mongoCol"></param>
 /// <param name="strKey"></param>
 /// <param name="keyField"></param>
 /// <returns></returns>
 public static Boolean DropDocument(MongoCollection mongoCol, object strKey, String keyField = "_id")
 {
     if (IsExistByKey(mongoCol, (BsonValue)strKey, keyField))
     {
         mongoCol.Remove(Query.EQ(keyField, (BsonValue)strKey));
     }
     return true;
 }
开发者ID:huohe2009,项目名称:MagicMongoDBTool,代码行数:15,代码来源:MongoDBHelper_Opration.cs

示例11: DropDocument

 /// <summary>
 ///     删除数据
 /// </summary>
 /// <param name="mongoCol"></param>
 /// <param name="strKey"></param>
 /// <returns></returns>
 public static String DropDocument(MongoCollection mongoCol, object strKey)
 {
     var result = new CommandResult(new BsonDocument());
     if (QueryHelper.IsExistByKey(mongoCol, (BsonValue)strKey))
     {
         try
         {
             result = mongoCol.Remove(Query.EQ(KEY_ID, (BsonValue) strKey), WriteConcern.Acknowledged);
         }
         catch (MongoCommandException ex)
         {
             result = ex.CommandResult;
         }
     }
     if (result.Response["err"] == BsonNull.Value)
     {
         return String.Empty;
     }
     return result.Response["err"].ToString();
 }
开发者ID:EricBlack,项目名称:MagicMongoDBTool,代码行数:26,代码来源:MongoDBHelper_Operation.cs

示例12: DeleteTestData

        /// <summary>
        /// 删除测试数据.
        /// </summary>
        /// <param name="collection"></param>
        private void DeleteTestData(MongoCollection<TestLinq> collection)
        {

            var query = Query<TestLinq>.GT(p => p.SeqNumber , 0);            
            collection.Remove(query);
        }
开发者ID:mahuidong,项目名称:my-csharp-sample,代码行数:10,代码来源:TestMongoLinq.cs

示例13: DropDocument

 /// <summary>
 /// 删除数据
 /// </summary>
 /// <param name="mongoCol"></param>
 /// <param name="strKey"></param>
 /// <param name="keyField"></param>
 /// <returns></returns>
 public static Boolean DropDocument(MongoCollection mongoCol, object strKey)
 {
     if (IsExistByKey(mongoCol, (BsonValue)strKey))
     {
         try
         {
             mongoCol.Remove(Query.EQ(KEY_ID, (BsonValue)strKey), new SafeMode(true));
         }
         catch (Exception)
         {
             return false;
         }
     }
     return true;
 }
开发者ID:kevan,项目名称:MagicMongoDBTool,代码行数:22,代码来源:MongoDBHelper_Operation.cs

示例14: NewMethod2

        private int NewMethod2(MongoCollection coll)
        {
            var v = coll.FindAs<BsonDocument>(Query.Null);
            Dictionary<string, string> results = new Dictionary<string, string>();
            List<BsonDocument> list = new List<BsonDocument>();
            List<string> oldID = new List<string>();
            foreach (var item in v)
            {
                BsonValue value;
                if (item.TryGetValue("_id", out value))
                {
                    string oldName = value.ToString();
                    string newName = ReplayceName(oldName);
                    if (oldName != newName)
                    {
                        oldID.Add(oldName);
                        item["_id"] = newName;
                        list.Add(item);
                    }
                }
            }
            foreach (var item in list)
            {
                coll.Save(item);
            }

            foreach (var item in oldID)
            {
                coll.Remove(Query.EQ("_id", item));
            }
            return results.Count;
        }
开发者ID:abel,项目名称:sinan,代码行数:32,代码来源:MinUserID.cs

示例15: DeleteClick

 static void DeleteClick(Click click, MongoCollection clicks)
 {
     var query = Query.EQ("_id", click.Id);
     clicks.Remove(query);
 }
开发者ID:quela,项目名称:myprojects,代码行数:5,代码来源:LocalMongoClicks.cs


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