Docs 菜单

Docs 主页开发应用程序MongoDB 驱动程序C#/.NET

插入多个文档

在此页面上

  • 例子
  • 预期结果
  • 更多信息
  • API 文档

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

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

选择 AsynchronousSynchronous 标签页,查看相应的代码。

运行上述任一完整示例后,输出结果如下:

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

如需了解有关使用生成器的更多信息,请参阅生成器操作

  • insertMany()

  • InsertManyAsync()

← 插入文档