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

插入多个文档

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

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

选择 Asynchronous 或 Synchronous 标签页,查看相应的代码。

// Generates 5 new restaurants by using a helper methodvar restaurants = GenerateDocuments(); // Asynchronously inserts the new documents into the restaurants collectionawait _restaurantsCollection.InsertManyAsync(restaurants);

有关 InsertManyAsync() 操作的完全可运行示例,请参阅 InsertManyAsync 代码示例。

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

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

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