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


C# IMongoCollection.FindOne方法代码示例

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


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

示例1: UserFavorite

        public UserFavorite(Database db, string username)
        {
            DB = db;
            UserFavoriteCollection = DB["UserFavorite"];

            // initial from db
            var spec = new Document() {
                    { "username", username }
                };

            InternalDocument = UserFavoriteCollection.FindOne(spec);

            if (InternalDocument == null)
            {
                InternalDocument = new Document { { "username", username } };
                DB["UserFavorite"].Insert(InternalDocument);
            }
        }
开发者ID:ningliaoyuan,项目名称:Antaeus,代码行数:18,代码来源:UserFavorite.cs

示例2: UpdateUsingAtomicIncrement

        /// <summary>
        /// Demoes Updates a single field using an atomic Increment ($inc) operator.
        /// </summary>
        /// <param name="orders">The orders.</param>
        private static void UpdateUsingAtomicIncrement(IMongoCollection orders)
        {
            Console.WriteLine("\n\n======= Update Document using Increment =======");

            var selector = new Document { { "CustomerName", "Daffy Duck" } };
            Console.WriteLine("Before Update: " + orders.FindOne(selector));

            // Add 2000 to order amount on document matching selector.
            orders.Update( new Document {{"$inc", new Document {{"OrderAmount", 2000}} }}, selector );

            Console.WriteLine("After Update: " + orders.FindOne(selector));
        }
开发者ID:ChrisEdwards,项目名称:IntroducingMongoDB,代码行数:16,代码来源:Program.cs

示例3: UpdateDocument

        /// <summary>
        /// Demo of Updating a document.
        /// </summary>
        /// <param name="orders">The orders.</param>
        private static void UpdateDocument( IMongoCollection orders )
        {
            Console.WriteLine( "\n\n======= Update Documents =======" );
            var selector = new Document {{"CustomerName", "Daffy Duck"}};
            Document docToUpdate = orders.FindOne( selector );

            Console.WriteLine( "Before Update: " + docToUpdate );

            // I'm in the money!
            docToUpdate["OrderAmount"] = 1000000.00;

            // Update Daffy's account before Hasaan finds him.
            orders.Update( docToUpdate );

            Console.WriteLine( "After Update: " + orders.FindOne( selector ) );
        }
开发者ID:ChrisEdwards,项目名称:IntroducingMongoDB,代码行数:20,代码来源:Program.cs

示例4: QueryFromCollection

        /// <summary>
        /// Demos querying the collection.
        /// </summary>
        /// <param name="orders">The orders.</param>
        private static void QueryFromCollection( IMongoCollection orders )
        {
            Console.WriteLine( "\n\n======= Query One Document =======" );
            // Create a specification to query the orders collection.
            var spec = new Document();
            spec["CustomerName"] = "Elmer Fudd";

            // Run the query.
            Document result = orders.FindOne( spec );
            Console.WriteLine( string.Format( "Found: {0}", result ) );
        }
开发者ID:ChrisEdwards,项目名称:IntroducingMongoDB,代码行数:15,代码来源:Program.cs


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