对于 AI 代理:可在 https://www.mongodb.com/zh-cn/docs/llms.txt 获取文档索引—通过在任何 URL 路径后添加 .md 可获取所有页面的 Markdown 版本。
Docs 菜单

插入多个文档

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

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

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

// 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

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