同期InsertMany()メソッドまたは非同期InsertManyAsync()メソッドを使用して、コレクションに複数のドキュメントを挿入できます。
例
次の例では、 restaurantsコレクションに複数のドキュメントを挿入しています。
AsynchronousSynchronous対応するコードを表示するには、 タブまたは タブを選択します。
// 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 コードサンプル を参照してください。
// Generates 5 new restaurants by using a helper methodvar 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詳細情報
ビルダの使用の詳細については、「 ビルダを使用した操作 」を参照してください。