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


C# IMongoCollection.InsertManyAsync方法代码示例

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


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

示例1: TestFixtureSetUp

        public void TestFixtureSetUp()
        {
            var client = DriverTestConfiguration.Client;
            var db = client.GetDatabase(DriverTestConfiguration.DatabaseNamespace.DatabaseName);
            db.DropCollectionAsync(DriverTestConfiguration.CollectionNamespace.CollectionName).GetAwaiter().GetResult();
            _collection = db.GetCollection<ZipEntry>(DriverTestConfiguration.CollectionNamespace.CollectionName);

            // This is a subset of the data from the mongodb docs zip code aggregation examples
            _collection.InsertManyAsync(new[]
            {
                new ZipEntry { Zip = "01053", City = "LEEDS", State = "MA", Population = 1350 },
                new ZipEntry { Zip = "01054", City = "LEVERETT", State = "MA", Population = 1748 },
                new ZipEntry { Zip = "01056", City = "LUDLOW", State = "MA", Population = 18820 },
                new ZipEntry { Zip = "01057", City = "MONSON", State = "MA", Population = 8194 },
                new ZipEntry { Zip = "36779", City = "SPROTT", State = "AL", Population = 1191 },
                new ZipEntry { Zip = "36782", City = "SWEET WATER", State = "AL", Population = 2444 },
                new ZipEntry { Zip = "36783", City = "THOMASTON", State = "AL", Population = 1527 },
                new ZipEntry { Zip = "36784", City = "THOMASVILLE", State = "AL", Population = 6229 },
            }).GetAwaiter().GetResult();
        }
开发者ID:RainsSoft,项目名称:mongo-csharp-driver,代码行数:20,代码来源:AggregationSample.cs

示例2: InsertDocumentsInCollection

 public async void InsertDocumentsInCollection(List<BsonDocument> documents, IMongoCollection<BsonDocument> collection)
 {
     await collection.InsertManyAsync(documents);
 }
开发者ID:AzharIqbal84,项目名称:ForwardMongoLogger,代码行数:4,代码来源:MongoDbHelper.cs

示例3: AddMovies

 private static void AddMovies(IMongoCollection<Movie> collection)
 {
     var movies = new List<Movie>
     {
         new Movie
         {
             Title = "The Perfect Developer",
             Category = "SciFi",
             Minutes = 118
         },
         new Movie
         {
             Title = "Lost In Frankfurt am Main",
             Category = "Horror",
             Minutes = 122
         },
         new Movie
         {
             Title = "The Infinite Standup",
             Category = "Horror",
             Minutes = 341
         }
     };
     //collection.InsertBatch(movies);
     collection.InsertManyAsync(movies).Wait();
 }
开发者ID:sjbgit,项目名称:mongo_map_reduce_net,代码行数:26,代码来源:Program.cs

示例4: Execute

 protected override void Execute(IMongoCollection<BsonDocument> collection, BsonDocument outcome, bool async)
 {
     if (async)
     {
         collection.InsertManyAsync(_documents).GetAwaiter().GetResult();
     }
     else
     {
         collection.InsertMany(_documents);
     }
 }
开发者ID:RavenZZ,项目名称:MDRelation,代码行数:11,代码来源:InsertManyTest.cs

示例5: Setup

        public void Setup()
        {
            _runner = MongoDbRunner.Start();
            var mongoUrlBuilder = new MongoUrlBuilder(_runner.ConnectionString);
            mongoUrlBuilder.DatabaseName = "AutomatedTest";

            //setup mongo database
            var client = new MongoClient(mongoUrlBuilder.ToMongoUrl());
            Database = client.GetDatabase(mongoUrlBuilder.DatabaseName);
            Collection = Database.GetCollection<RootEntity>("Root");
            ContainsNotProvidedTagsEntityId = ObjectId.GenerateNewId();
            SubEntityId = ObjectId.GenerateNewId();

            //add mock data
            var entities = new List<RootEntity>()
            {
                new RootEntity()
                {
                    Id = ObjectId.GenerateNewId(),
                    Tags = new List<string>() {"tag1"},
                    SubCollection = new List<SubEntity>()
                    {
                        new SubEntity()
                        {
                            Id = SubEntityId
                        }
                    }
                },
                new RootEntity()
                {
                    Id = ContainsNotProvidedTagsEntityId,
                    Tags = new List<string>() {"tag1", "tag2"},
                    SubCollection = new List<SubEntity>()
                    {
                        new SubEntity()
                        {
                            Id = SubEntityId
                        }
                    }
                }
            };
            Collection.InsertManyAsync(entities).Wait();
        }
开发者ID:nickmkk,项目名称:UpdateWhereItemsArentInProvidedList,代码行数:43,代码来源:RemoveSubEntityServiceTests.cs

示例6: AddDocuments

        static async Task AddDocuments(IMongoCollection<Person> collection)
        {
            var testdoc = new Person ("jones");
            testdoc.Age = 30;
            testdoc.Profession = "hacker";

            var nestedArray = new List<string>();
            nestedArray.Add("color");
            nestedArray.Add("red");
            testdoc.Preferences = nestedArray;
            await collection.InsertOneAsync(testdoc);
            Console.WriteLine("Adding:" + testdoc.ToBsonDocument().ToString());

            var testdoc2 = new Person("jones");
            testdoc2.Age = 50;
            testdoc2.Profession = "retired hacker";
            await collection.InsertOneAsync(testdoc2);
            Console.WriteLine("Adding:" + testdoc2.ToBsonDocument().ToString());

            var doc2 = new Person("Smith");
            var doc3 = new Person("White");
            await collection.InsertManyAsync(new[] { doc2, doc3 });
            Console.WriteLine("Adding:" + doc2.ToBsonDocument().ToString() + "\nAdding:" + doc3.ToBsonDocument().ToString());
        }
开发者ID:ax2015,项目名称:testprojects,代码行数:24,代码来源:Program.cs

示例7: InitializeCollectionAsync

 private async Task InitializeCollectionAsync(IMongoCollection<BsonDocument> collection, List<BsonDocument> documents)
 {
     await collection.DeleteManyAsync(new BsonDocument());
     if (documents.Count > 0)
     {
         await collection.InsertManyAsync(documents);
     }
 }
开发者ID:robblovell,项目名称:mongo-csharp-driver,代码行数:8,代码来源:GridFSTestBase.cs

示例8: ExecuteAsync

 protected override Task ExecuteAsync(IMongoCollection<BsonDocument> collection, BsonDocument outcome)
 {
     return collection.InsertManyAsync(_documents);
 }
开发者ID:kay-kim,项目名称:mongo-csharp-driver,代码行数:4,代码来源:InsertManyTest.cs

示例9: InsertManyAsync

        /// <summary>
        /// Insert two documents (SQL=row) in the collection (SQL=table) as a single operation.
        /// </summary>
        private static async Task InsertManyAsync(IMongoCollection<BsonDocument> collection)
        {
            Console.WriteLine("\n++ Insert two documents (SQL=row) in the collection (SQL=table) as a single operation.");

            var document1 = new BsonDocument(newObj);
            // [MONGODB-DEMO] NoSQL is Unstructured (schemaless) - document1 and document2 have different set of key-value pairs.
            // [MONGODB-DEMO] There is no unique key '_id' (BsonObjectId) in document2 - will be generated by MongoDB automatically.
            var document2 = new BsonDocument
                {
                    //{ "_id",        ObjectId.GenerateNewId() },
                    { "Name",        "Sergii"},
                    { "Surname",     "Shevchenko"},
                    { "Extra info",  "Phone: 3432 523 59"}
                };
            await collection.InsertManyAsync(new [] {document1, document2});
        }
开发者ID:sshev4enko,项目名称:tandd,代码行数:19,代码来源:Program.cs

示例10: InsertManyAsync

 public async static void InsertManyAsync(IMongoCollection<BsonDocument> collection, IEnumerable<BsonDocument> input)
 {
     await collection.InsertManyAsync(input);
 }
开发者ID:BertiFuchsi,项目名称:GanovenFutter,代码行数:4,代码来源:Connector.cs


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