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


C# MongoCollection类代码示例

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


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

示例1: AddUserEx

 /// <summary>
 ///     Adds a user to this database.
 /// </summary>
 /// <param name="user">The user.</param>
 public static void AddUserEx(MongoCollection Col, User user)
 {
     var document = Col.FindOneAs<BsonDocument>(Query.EQ("user", user.Username));
     if (document == null)
     {
         document = new BsonDocument("user", user.Username);
     }
     document["roles"] = user.roles;
     if (document.Contains("readOnly"))
     {
         document.Remove("readOnly");
     }
     //必须要Hash一下Password
     document["pwd"] = MongoUser.HashPassword(user.Username, user.Password);
     //OtherRole 必须放在Admin.system.users里面
     if (Col.Database.Name == MongoDbHelper.DATABASE_NAME_ADMIN)
     {
         document["otherDBRoles"] = user.otherDBRoles;
     }
     if (string.IsNullOrEmpty(user.Password))
     {
         document["userSource"] = user.userSource;
     }
     Col.Save(document);
 }
开发者ID:EricBlack,项目名称:MagicMongoDBTool,代码行数:29,代码来源:User.cs

示例2: ChooseAction

        private static void ChooseAction(MongoCollection<Word> words)
        {
            string action = Console.ReadLine();

            switch (action)
            {
                case "1":
                    ReadWord(words);
                    break;
                case "2":
                    ListWords(words);
                    break;
                case "3":
                    FindWords(words);
                    break;
                case "4":
                    DisplayStartupMenu();
                    break;
                case "exit":
                    Console.WriteLine("Goodbuy!");
                    return;
                default:
                    Console.WriteLine("Invalid action, please choose again.");
                    break;
            }

            ChooseAction(words);
        }
开发者ID:hristo-iliev,项目名称:TelerikHW,代码行数:28,代码来源:MongoDictionary.cs

示例3: FromLevel1RecordCollectionToLevelTopRecords

        /// <summary>
        /// LevelTop只能有一个
        /// </summary>
        /// <param name="flight"></param>
        /// <param name="collection"></param>
        /// <returns></returns>
        public LevelTopFlightRecord FromLevel1RecordCollectionToLevelTopRecords(
            Flight flight, MongoCollection<Level1FlightRecord> collection)
        {
            FlightParameter[] parameters = this.GetParameters();
            Dictionary<string, LevelTopFlightRecord> topRecordMaps = new Dictionary<string, LevelTopFlightRecord>();
            Dictionary<LevelTopFlightRecord, List<Level2FlightRecord>> level2RecordMap
                = new Dictionary<LevelTopFlightRecord, List<Level2FlightRecord>>();
            List<LevelTopFlightRecord> topRecords = new List<LevelTopFlightRecord>();

            foreach (FlightParameter para in parameters)
            {
                LevelTopFlightRecord topRecord = new LevelTopFlightRecord()
                {
                    StartSecond = flight.StartSecond,
                    EndSecond = flight.EndSecond,
                    ParameterID = para.ParameterID,
                };

                topRecordMaps.Add(para.ParameterID, topRecord);
                level2RecordMap.Add(topRecord, new List<Level2FlightRecord>());

                for (int currentSecond = flight.StartSecond; currentSecond > flight.EndSecond; currentSecond += SecondGap)
                {
                    int step = SecondGap;
                    Level2FlightRecord level2 = this.HandleOneStep(currentSecond, step, para,
                         topRecord, flight, collection);

                    level2RecordMap[topRecord].Add(level2);
                }
            }

            return null;//DEBUG
            //return topRecords.ToArray();
        }
开发者ID:K-Library-NET,项目名称:PopcornStudios,代码行数:40,代码来源:DefaultLevel1ToLevelTopRecordStrategy.cs

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

示例5: MongoInsertOptions

 /// <summary>
 /// Initializes a new instance of the MongoInsertOptions class.
 /// </summary>
 /// <param name="collection">The collection from which to get default settings for the options.</param>
 public MongoInsertOptions(
     MongoCollection collection
 ) {
     this.checkElementNames = true;
     this.flags = InsertFlags.None;
     this.safeMode = collection.Settings.SafeMode;
 }
开发者ID:snedzad,项目名称:mongo-csharp-driver,代码行数:11,代码来源:MongoInsertOptions.cs

示例6: UpdateDocument

 public override void UpdateDocument(MongoCollection<BsonDocument> collection, BsonDocument document)
 {
     var projectIds = document.GetValue("ProjectIds").AsBsonArray.Select(p => p.AsInt32).ToList();
     document.Remove("ProjectIds");
     document.Add("ProjectIds", new BsonArray(projectIds.Select(x => x.ToString())));
     collection.Save(document);
 }
开发者ID:apxnowhere,项目名称:Encore,代码行数:7,代码来源:ChangeFieldProjectIdToString.cs

示例7: Run

        public IEnumerable<BsonDocument> Run(MongoCollection<Rental> rentals)
        {
            var priceRange = new BsonDocument(
                "$subtract",
                new BsonArray
                {
                    "$Price",
                    new BsonDocument(
                        "$mod",
                        new BsonArray{"$Price",500}
                        )
                });
            var grouping =new BsonDocument(
                "$group",
                new BsonDocument
                {
                    {"_id",priceRange},
                    {"count",new BsonDocument("$sum",1)}
                });
            var sort=new BsonDocument(
                "$sort",
                new BsonDocument("_id",1)
                );

            var args=new AggregateArgs
            {
                Pipeline=new []{grouping,sort}
            };

            return rentals.Aggregate(args);
        }
开发者ID:nywebman,项目名称:MongoDBdotNet,代码行数:31,代码来源:QueryPriceDistribution.cs

示例8: TestFixtureSetup

 public void TestFixtureSetup()
 {
     _database = Configuration.TestDatabase;
     var collectionSettings = new MongoCollectionSettings() { GuidRepresentation = GuidRepresentation.Standard };
     _collection = _database.GetCollection<C>("csharp714", collectionSettings);
     _collection.Drop();
 }
开发者ID:GGsus,项目名称:mongo-csharp-driver,代码行数:7,代码来源:CSharp714Tests.cs

示例9: Find

        public IEnumerable<IDictionary<string, object>> Find(MongoCollection<BsonDocument> collection, SimpleQuery query, out IEnumerable<SimpleQueryClauseBase> unhandledClauses)
        {
            var builder = MongoQueryBuilder.BuildFrom(query);

            unhandledClauses = builder.UnprocessedClauses;

            if (builder.IsTotalCountQuery)
            {
                long count;
                if (builder.Criteria == null)
                    count = collection.Count();
                else
                    count = collection.Count(_expressionFormatter.Format(builder.Criteria));

                //TODO: figure out how to make count a long
                builder.SetTotalCount((int)count);
            }

            if (!builder.SkipCount.HasValue && builder.TakeCount.HasValue && builder.TakeCount.Value == 1)
                return new[] { FindOne(collection, builder.Criteria) };

            var cursor = CreateCursor(collection, builder.Criteria);

            ApplyFields(cursor, builder.Columns);
            ApplySorting(cursor, builder.Order);
            ApplySkip(cursor, builder.SkipCount);
            ApplyTake(cursor, builder.TakeCount);

            var aliases = builder.Columns.OfType<ObjectReference>().ToDictionary(x => ExpressionFormatter.GetFullName(x), x => x.GetAlias());

            return cursor.Select(x => x.ToSimpleDictionary(aliases));
        }
开发者ID:kppullin,项目名称:Simple.Data.MongoDB,代码行数:32,代码来源:MongoAdapterFinder.cs

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

示例11: GetAroundYouArticles

        private IEnumerable<ArticleWebDto> GetAroundYouArticles(
            MongoCollection<ArticleDto> articles,
            string lngString,
            string latString,
            CultureInfo culture)
        {
            var innerMaxDistance = 3.0d;
            var outerMaxDistance = 5.0d;

            var innerMaxDistanceString = (innerMaxDistance / EarthRadius).ToString(culture.NumberFormat);
            var outerMaxDistanceString = (outerMaxDistance / EarthRadius).ToString(culture.NumberFormat);

            var jsonQuery = "{$and:[ " +
                "{'location':{$geoWithin:{$centerSphere:[[" + lngString + "," + latString + "]," + outerMaxDistanceString + "]}}}," +
                "{'location':{$not:{$geoWithin:{$centerSphere:[[" + lngString + "," + latString + "]," + innerMaxDistanceString + "]}}} }," +
            "]}";

            var doc = BsonSerializer.Deserialize<BsonDocument>(jsonQuery);
            var query = new QueryDocument(doc);
            var results = articles.Find(query).SetSortOrder(new SortByBuilder().Descending("publishedAt")).SetLimit(50);

            var dtos = results.ToList().Select(ConvertArticleDtoToArticleWebDto());

            return dtos;
        }
开发者ID:Cosmo,项目名称:News-Sightseeing,代码行数:25,代码来源:DiscoverController.cs

示例12: frmQuery

 /// <summary>
 /// 初始化
 /// </summary>
 /// <param name="mDataViewInfo">Filter也是DataViewInfo的一个属性,所以这里加上参数</param>
 public frmQuery(MongoDBHelper.DataViewInfo mDataViewInfo)
 {
     InitializeComponent();
     CurrentDataViewInfo = mDataViewInfo;
     SystemManager.SelectObjectTag = mDataViewInfo.strDBTag;
     _mongoCol = SystemManager.GetCurrentCollection();
 }
开发者ID:china0zzl,项目名称:MagicMongoDBTool,代码行数:11,代码来源:frmQuery.cs

示例13: TestFixtureSetup

 public void TestFixtureSetup()
 {
     _server = Configuration.TestServer;
     _database = Configuration.TestDatabase;
     _collection = Configuration.TestCollection;
     _collection.Drop();
 }
开发者ID:annikulin,项目名称:code-classifier,代码行数:7,代码来源:CSharp282Tests.cs

示例14: Setup

 public void Setup()
 {
     server = MongoServer.Create("mongodb://localhost/?safe=true");
     server.Connect();
     database = server["onlinetests"];
     collection = database["testcollection"];
 }
开发者ID:modesto,项目名称:mongo-csharp-driver,代码行数:7,代码来源:MongoCollectionTests.cs

示例15: EstablishConnection

 public static void EstablishConnection()
 {
     client = new MongoClient(connectionString);
     server = client.GetServer();
     database = server.GetDatabase(DbName);
     entries = database.GetCollection<JSonReport>(collectionName);
 }
开发者ID:VyaraGGeorgieva,项目名称:TelerikAcademy,代码行数:7,代码来源:MongoDbReportReader.cs


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