本文整理汇总了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();
}
示例2: InsertDocumentsInCollection
public async void InsertDocumentsInCollection(List<BsonDocument> documents, IMongoCollection<BsonDocument> collection)
{
await collection.InsertManyAsync(documents);
}
示例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();
}
示例4: Execute
protected override void Execute(IMongoCollection<BsonDocument> collection, BsonDocument outcome, bool async)
{
if (async)
{
collection.InsertManyAsync(_documents).GetAwaiter().GetResult();
}
else
{
collection.InsertMany(_documents);
}
}
示例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();
}
示例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());
}
示例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);
}
}
示例8: ExecuteAsync
protected override Task ExecuteAsync(IMongoCollection<BsonDocument> collection, BsonDocument outcome)
{
return collection.InsertManyAsync(_documents);
}
示例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});
}
示例10: InsertManyAsync
public async static void InsertManyAsync(IMongoCollection<BsonDocument> collection, IEnumerable<BsonDocument> input)
{
await collection.InsertManyAsync(input);
}