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


C# IMongoCollection.Insert方法代码示例

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


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

示例1: OnInit

 public override void OnInit()
 {
     _collection = DB["mr"];
     _collection.Insert(new Document().Add("_id", 1).Add("tags", new[] {"dog", "cat"}));
     _collection.Insert(new Document().Add("_id", 2).Add("tags", new[] {"dog"}));
     _collection.Insert(new Document().Add("_id", 3).Add("tags", new[] {"mouse", "cat", "dog"}));
     _collection.Insert(new Document().Add("_id", 4).Add("tags", new String[] {}));
 }
开发者ID:jango2015,项目名称:MongoDB_Client_.Net,代码行数:8,代码来源:TestMapReduce.cs

示例2: OnInit

 public override void OnInit()
 {
     mrcol = DB["mr"];
     mrcol.Insert(new Document().Append("_id", 1).Append("tags", new String[]{"dog", "cat"}));
     mrcol.Insert(new Document().Append("_id", 2).Append("tags", new String[]{"dog"}));
     mrcol.Insert(new Document().Append("_id", 3).Append("tags", new String[]{"mouse", "cat", "dog"}));
     mrcol.Insert(new Document().Append("_id", 4).Append("tags", new String[]{}));
 }
开发者ID:kvnsmth,项目名称:mongodb-csharp,代码行数:8,代码来源:TestMapReduceBuilder.cs

示例3: TestSetup

        public void TestSetup()
        {
            personCollection = this.DB.GetCollection<Person>("people");
            personCollection.Delete(new { }, true);
            personCollection.Insert(new Person { FirstName = "Bob", LastName = "McBob", Age = 42, Address = new Address { City = "London" }, Aliases = new[]{"Blub"} }, true);
            personCollection.Insert(new Person { FirstName = "Jane", LastName = "McJane", Age = 35, Address = new Address { City = "Paris" } }, true);
            personCollection.Insert(new Person { FirstName = "Joe", LastName = "McJoe", Age = 21, Address = new Address { City = "Chicago" } }, true);

            orgCollection = this.DB.GetCollection<Organization>("orgs");
            orgCollection.Delete(new { }, true);
            orgCollection.Insert(new Organization { Name = "The Muffler Shanty", Address = new Address { City = "London" } }, true);
        }
开发者ID:jango2015,项目名称:MongoDB_Client_.Net,代码行数:12,代码来源:LinqExtensionsTests.cs

示例4: GeospatialTests

        public GeospatialTests()
        {
            _server = Mongo.Create("mongodb://localhost/NormTests?pooling=false");
            _collection = _server.GetCollection<GeoTestClass>("LatLngTests");

            _collection.Insert(new GeoTestClass { Location = new LatLng { Latitude = 57.1056, Longitude = 12.2508 }, Name = "Varberg"});
            _collection.Insert(new GeoTestClass { Location = new LatLng { Latitude = 57.7, Longitude = 11.9166667 }, Name = "Gothenburg" }); //  ~70km North of Varberg
            _collection.Insert(new GeoTestClass { Location = new LatLng { Latitude = 29.950975, Longitude = -90.081217 }, Name = "New Orleans Saints" });
            _collection.Insert(new GeoTestClass { Location = new LatLng { Latitude = 44.973876, Longitude = -93.258133 }, Name = "Minnesota Vikings" });
            _collection.Insert(new GeoTestClass { Location = new LatLng { Latitude = 0, Longitude = 0 }, Name = "Center of the Earth" });
            _collection.CreateGeoIndex(geo => geo.Location, "loc", true);
        }
开发者ID:hafstrom,项目名称:NoRM,代码行数:12,代码来源:GeospatialTests.cs

示例5: QueryTests

 public QueryTests()
 {
     var admin = new MongoAdmin("mongodb://localhost/admin?pooling=false&strict=true");
     _server = Mongo.Create("mongodb://localhost/NormTests?pooling=false");
     _collection = _server.GetCollection<Person>("People");
     _buildInfo = admin.BuildInfo();
     //cause the collection to exist on the server by inserting, then deleting some things.
     _collection.Insert(new Person());
     _collection.Delete(new { });
 }
开发者ID:gaoninggn,项目名称:NoRM,代码行数:10,代码来源:QueryTests.cs

示例6: CreateAndInsertDocumentIntoCollection

        /// <summary>
        /// Inserts a new document.
        /// </summary>
        /// <param name="orders">The orders.</param>
        private static void CreateAndInsertDocumentIntoCollection(IMongoCollection orders)
        {
            // Create a new order.
            var order = new Document();
            order["orderAmount"] = 57.22;
            order["customerName"] = "Elmer Fudd";

            // Add the new order to the mongo orders colleciton.
            orders.Insert(order);
            Console.WriteLine(string.Format("Inserted: {0}", order));
        }
开发者ID:ChrisEdwards,项目名称:IntroducingMongoDB,代码行数:15,代码来源:Program.cs

示例7: CreateAndInsertSingleDocumentIntoCollection

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

            // Create a new order.
            var order = new Document();
            order["OrderAmount"] = 57.22;
            order["CustomerName"] = "Elmer Fudd";

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

            Console.WriteLine( string.Format( "Document Count After Insert: [ {0} ]", orders.Count() ) );
        }
开发者ID:ChrisEdwards,项目名称:IntroducingMongoDB,代码行数:20,代码来源:Program.cs

示例8: CreateAndInsertMultipleDocumentIntoCollection

        /// <summary>
        /// Demo inserting multiple document into collection.
        /// </summary>
        /// <param name="orders">The orders.</param>
        private static void CreateAndInsertMultipleDocumentIntoCollection( IMongoCollection 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 Document();
            order1["OrderAmount"] = 100.23;
            order1["CustomerName"] = "Bugs Bunny";

            var order2 = new Document();
            order2["OrderAmount"] = 0.01;
            order2["CustomerName"] = "Daffy Duck";

            IEnumerable< Document > orderList = new List< Document > {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() ) );
        }
开发者ID:ChrisEdwards,项目名称:IntroducingMongoDB,代码行数:27,代码来源:Program.cs

示例9: Setup

        /// <summary>
        ///   Setup the collection and insert some data into it.
        /// </summary>
        public void Setup()
        {
            var connstr = ConfigurationManager.AppSettings["simple"];
            if(String.IsNullOrEmpty(connstr))
                throw new ArgumentNullException("Connection string not found.");
            mongo = new Mongo(connstr);
            mongo.Connect();
            simple = mongo["simple"];
            categories = simple.GetCollection<Document>("categories");
            Clean();

            var names = new[] {"Bluez", "Jazz", "Classical", "Rock", "Oldies", "Heavy Metal"};
            foreach(var name in names)
                categories.Insert(new Document {{"name", name}});
        }
开发者ID:gaoninggn,项目名称:mongodb-csharp,代码行数:18,代码来源:Main.cs


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