文档菜单
文档首页
/ / /
C#/.NET
/

插入多个文档

在本页

  • 示例
  • 预期结果
  • 附加信息
  • API 文档

您可以使用同步的InsertMany() 方法或异步的 InsertManyAsync() 方法将多个文档插入到集合中。

以下示例将多个文档插入到 restaurants 集合中。

选择异步同步 选项卡以查看相应的代码。

// Generates 5 new restaurants by using a helper method
var restaurants = GenerateDocuments();
// Asynchronously inserts the new documents into the restaurants collection
await _restaurantsCollection.InsertManyAsync(restaurants);

要查看 InsertManyAsync() 操作的完整可运行示例,请参阅InsertManyAsync 代码示例.

// Generates 5 new restaurants by using a helper method
var restaurants = GenerateDocuments();
// Inserts the new documents into the restaurants collection
_restaurantsCollection.InsertMany(restaurants);

关于 InsertMany() 操作的完整可运行示例,请参阅以下 InsertMany 代码示例。

在运行上述任意完整示例之后,输出如下

Number of restaurants found before insert: 0
Inserting documents...
Number of restaurants inserted: 5

要了解更多关于使用构建器的信息,请参阅使用构建器执行的操作.

返回

插入文档