Ejemplo n.º 1
0
        /// <summary>
        /// Demo inserting multiple document into collection.
        /// </summary>
        /// <param name="orders">The orders.</param>
        private static void CreateAndInsertMultipleDocumentIntoCollection(MongoCollection<Order> orders)
        {
            Console.WriteLine("\n\n======= Insert Multiple Documents =======");
            Console.WriteLine(string.Format("Document Count Before Insert: [ {0} ]", orders.Count()));

            // Create new orders.
            var order1 = new Order
                         	{
                         			OrderAmount = 100.23,
                         			CustomerName = "Bugs Bunny"
                         	};
            var order2 = new Order
                         	{
                         			OrderAmount = 0.01,
                         			CustomerName = "Daffy Duck"
                         	};

            IEnumerable<Order> orderList = new List<Order> { order1, order2 };

            // Insert an IEnumerable.
            orders.Insert(orderList);

            Console.WriteLine(string.Format("Inserted: {0}", order1));
            Console.WriteLine(string.Format("Inserted: {0}", order2));

            Console.WriteLine(string.Format("Document Count After Insert: [ {0} ]", orders.Count()));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Inserts a new document.
        /// </summary>
        /// <param name="collection">The orders.</param>
        private static void CreateAndInsertSingleDocumentIntoCollection(MongoCollection<Order> collection)
        {
            Console.WriteLine("\n\n======= Insert Multiple Documents =======");
            Console.WriteLine(string.Format("Document Count Before Insert: [ {0} ]", collection.Count()));

            // Create a new order.
            var order = new Order()
                            {
                                    OrderAmount = 57.22,
                                    CustomerName = "Elmer Fudd"
                            };

            // Add the new order to the mongo orders colleciton.
            collection.Insert(order);
            Console.WriteLine(string.Format("Inserted: {0}", order));

            Console.WriteLine(string.Format("Document Count After Insert: [ {0} ]", collection.Count()));
        }