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


C# MongoCollection.FindAs方法代码示例

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


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

示例1: AddToDictionary

 private static void AddToDictionary(MongoCollection english)
 {
     Console.WriteLine("Enter word.");
     string word = Console.ReadLine();
     Console.WriteLine("Enter translation.");
     string translation = Console.ReadLine();
     if (!string.IsNullOrWhiteSpace(word) && !string.IsNullOrWhiteSpace(translation))
     {
         var query = Query.And(Query.EQ("Name", word));
         var filtered = english.FindAs<Word>(query);
         var count = filtered.Count();
         if (count == 0)
         {
             english.Insert(new Word(word, translation));
             Console.WriteLine("The word {0} is added.", word);
         }
         else
         {
             Console.WriteLine("The word {0} is already added.", word);
         }
     }
     else
     {
         Console.WriteLine("You enter null or empty string for word or translation. Please try again.");
     }
 }
开发者ID:vasilkrvasilev,项目名称:Databases,代码行数:26,代码来源:MongoDbDictionary.cs

示例2: ChangeTranslation

 private static void ChangeTranslation(MongoCollection english)
 {
     Console.WriteLine("Enter word.");
     string word = Console.ReadLine();
     Console.WriteLine("Enter translation.");
     string translation = Console.ReadLine();
     if (!string.IsNullOrWhiteSpace(word) && !string.IsNullOrWhiteSpace(translation))
     {
         var query = Query.And(Query.EQ("Name", word));
         var filtered = english.FindAs<Word>(query);
         var count = filtered.Count();
         if (count > 0)
         {
             foreach (var item in filtered)
             {
                 var update = Update.Set("Translation", translation);
                 var queryId = Query.EQ("_id", item.Id);
                 english.Update(queryId, update);
                 Console.WriteLine("Translation of the word {0} is changed.", word);
             }
         }
         else
         {
             Console.WriteLine("There is no word {0}.", word);
         }
     }
     else
     {
         Console.WriteLine("You enter null or empty string for word or translation. Please try again.");
     }
 }
开发者ID:vasilkrvasilev,项目名称:Databases,代码行数:31,代码来源:MongoDbDictionary.cs

示例3: find

        public dynamic find(MongoCollection collection,object[] args)
        {
            Type type = args[0].GetType();

            if(type.Name.Contains("<>__AnonType")){

                PropertyInfo[] properties = type.GetProperties();
                Dictionary<string,object> dictionary = new Dictionary<string, object>();
                foreach(var property in properties)
                    dictionary[property.Name] = property.GetValue(args[0],null);

                var query = new QueryDocument(dictionary);
                var result = collection.FindAs<BsonDocument>(query);
                List<Entity> documents = new List<Entity>();

                if(result.Size() > 0)
                {
                    foreach(var entity in result)
                        documents.Add(new Entity(entity));
                }

                return documents;
            }
            throw new NotImplementedException("Only annonymous types are accepted for Queries.");
        }
开发者ID:blackorzar,项目名称:DMongo,代码行数:25,代码来源:DBExpando.cs

示例4: ExportToFile

 /// <summary>
 ///     ExportToFile
 /// </summary>
 /// <param name="currentDataViewInfo"></param>
 /// <param name="excelFileName"></param>
 /// <param name="exportType"></param>
 /// <param name="mongoCol"></param>
 public static void ExportToFile(DataViewInfo currentDataViewInfo,
     string excelFileName,
     EnumMgr.ExportType exportType,
     MongoCollection mongoCol)
 {
     MongoCursor<BsonDocument> cursor;
     //Query condition:
     if (currentDataViewInfo != null && currentDataViewInfo.IsUseFilter)
     {
         cursor = mongoCol.FindAs<BsonDocument>(
             QueryHelper.GetQuery(currentDataViewInfo.MDataFilter.QueryConditionList))
             .SetFields(QueryHelper.GetOutputFields(currentDataViewInfo.MDataFilter.QueryFieldList))
             .SetSortOrder(QueryHelper.GetSort(currentDataViewInfo.MDataFilter.QueryFieldList));
     }
     else
     {
         cursor = mongoCol.FindAllAs<BsonDocument>();
     }
     var dataList = cursor.ToList();
     switch (exportType)
     {
         case EnumMgr.ExportType.Excel:
             //ExportToExcel(dataList, ExcelFileName);
             GC.Collect();
             break;
         case EnumMgr.ExportType.Text:
             ExportToJson(dataList, excelFileName, MongoHelper.JsonWriterSettings);
             break;
         case EnumMgr.ExportType.Xml:
             break;
     }
     MongoHelper.OnActionDone(new ActionDoneEventArgs(" Completed "));
 }
开发者ID:jango2015,项目名称:MongoCola,代码行数:40,代码来源:ExportImport.cs

示例5: NewMethod

 private int NewMethod(MongoCollection coll, string fbname)
 {
     var v = coll.FindAs<BsonDocument>(Query.Null).SetFields(fbname);
     Dictionary<BsonValue, string> results = new Dictionary<BsonValue, string>();
     foreach (var item in v)
     {
         BsonValue value;
         if (item.TryGetValue(fbname, out value))
         {
             string oldName = value.ToString();
             string newName = ReplayceName(oldName);
             if (oldName != newName)
             {
                 item.TryGetValue("_id", out value);
                 results.Add(value, newName);
             }
         }
     }
     foreach (var item in results)
     {
         BsonValue id = item.Key;
         string newName = item.Value;
         try
         {
             Query.EQ("_id", id);
             Update.Set(fbname, newName);
             coll.Update(Query.EQ("_id", id), Update.Set(fbname, newName), SafeMode.False);
         }
         catch (System.Exception ex)
         {
             LogWrapper.Error("renameErr:" + id + " newName" + newName, ex);
         }
     }
     return results.Count;
 }
开发者ID:abel,项目名称:sinan,代码行数:35,代码来源:MinUserID.cs

示例6: FindDescriptionByBookName

        public static void FindDescriptionByBookName(MongoCollection dictonary, string bookName)
        {
            var searchQuery = Query.EQ("Name", bookName);

            var queryResult = dictonary.FindAs<Entry>(searchQuery);

            Console.WriteLine("Search");
            Console.WriteLine(new string('-', Console.WindowWidth - 5));

            foreach (var item in queryResult)
            {
                Console.WriteLine("Book Name: {0}, Transalation: {1}", item.Name, item.Translation);
            }
        }
开发者ID:HansS,项目名称:TelerikAcademy-homework,代码行数:14,代码来源:Program.cs

示例7: Run

 /// <summary>
 ///     运行
 /// </summary>
 /// <returns></returns>
 public override int Run()
 {
     _processCollection = (MongoCollection)PlugObj;
     if (RuntimeMongoDbContext.CollectionFilter.ContainsKey(_processCollection.Name))
     {
         var filter = RuntimeMongoDbContext.CollectionFilter[_processCollection.Name].QueryConditionList;
         Export(_processCollection.FindAs<BsonDocument>(QueryHelper.GetQuery(filter)).ToList(), _processCollection.Name);
     }
     else
     {
         Export(_processCollection.FindAllAs<BsonDocument>().ToList(), _processCollection.Name);
     }
     MessageBox.Show(_processCollection.Name);
     return Success;
 }
开发者ID:magicdict,项目名称:MongoCola,代码行数:19,代码来源:ExportToExcel.cs

示例8: ShowTranslation

 private static void ShowTranslation(MongoCollection english)
 {
     Console.WriteLine("Enter word");
     string word = Console.ReadLine();
     if (!string.IsNullOrWhiteSpace(word))
     {
         var query = Query.And(Query.EQ("Name", word));
         var filtered = english.FindAs<Word>(query);
         var count = filtered.Count();
         if (count > 0)
         {
             Console.WriteLine("Translation of the word {0} is:", filtered.First().Name);
             Console.WriteLine(filtered.First().Translation);
         }
         else
         {
             Console.WriteLine("There is no word {0}.", word);
         }
     }
     else
     {
         Console.WriteLine("You enter null or empty string for word. Please try again.");
     }
 }
开发者ID:vasilkrvasilev,项目名称:Databases,代码行数:24,代码来源:MongoDbDictionary.cs

示例9: IsExistByKey

 /// <summary>
 /// Is Exist by Key
 /// </summary>
 /// <param name="mongoCol">Collection</param>
 /// <param name="KeyValue">KeyValue</param>
 /// <param name="Field">KeyField</param>
 /// <returns></returns>
 public static Boolean IsExistByKey(MongoCollection mongoCol, BsonValue KeyValue)
 {
     return mongoCol.FindAs<BsonDocument>(Query.EQ(KEY_ID, KeyValue)).Count() > 0;
 }
开发者ID:Eddie0330,项目名称:MagicMongoDBTool,代码行数:11,代码来源:MongoDBHelper_Query.cs

示例10: ApplicationDbContext

 public ApplicationDbContext(MongoCollection usersCollection, MongoCollection rolesCollection, MongoCollection clainsCollection, MongoCollection clientCollection)
     : base(usersCollection, rolesCollection, clainsCollection, clientCollection)
 {
     Clients = clientCollection.FindAs<IdentityClient>(null).ToList();
     Claims = clainsCollection.FindAs<IdentityClaim>(null).ToList();
 }
开发者ID:jornfilho,项目名称:identity-2.1,代码行数:6,代码来源:ApplicationDbContext.cs

示例11: IsExistByField

 /// <summary>
 /// 是否存在某个数据
 /// </summary>
 /// <param name="Field"></param>
 /// <param name="mongoCol"></param>
 /// <returns></returns>
 public static Boolean IsExistByField(MongoCollection mongoCol, BsonValue strKey, string Field = "_id")
 {
     return mongoCol.FindAs<BsonDocument>(Query.EQ(Field, strKey)).Count() > 0;
 }
开发者ID:seaman,项目名称:MagicMongoDBTool,代码行数:10,代码来源:MongoDBHelper_Query.cs

示例12: 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

示例13: ListClicks

        static List<Click> ListClicks(MongoCollection clicks, int minX = 0, int maxX = int.MaxValue, int minY = 0, int maxY = int.MaxValue)
        {
            var query = Query.And(Query.GTE("Location.X", minX), Query.GTE("Location.Y", minY), Query.LTE("Location.X", maxX), Query.LTE("Location.X", maxY));

            //This operation risks an exception if the element is not exactly a Click object (e.g. has an added field). To be safe, use BsonDocument as a type
            var filteredClicks = clicks.FindAs<Click>(query);
            int index = 0;

            var listedClicks = new List<Click>();

            foreach (var click in filteredClicks)
            {
                Console.WriteLine(index + ". " + click.ToString());
                index++;
                listedClicks.Add(click);
            }

            return listedClicks;
        }
开发者ID:quela,项目名称:myprojects,代码行数:19,代码来源:LocalMongoClicks.cs


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