Exemplo n.º 1
0
            /// <summary>
            /// Inserts one or more documents in the collection.
            /// </summary>
            /// <param name="docs">The documents to insert.</param>
            /// <returns>
            /// An awaitable <see cref="Task{T}"/> representing the remote insert many operation. The result of the task
            /// contains the <c>_id</c>s of the inserted documents.
            /// </returns>
            /// <seealso href="https://docs.mongodb.com/manual/reference/method/db.collection.insertMany/"/>
            public async Task <InsertManyResult> InsertManyAsync(IEnumerable <TDocument> docs)
            {
                Argument.NotNull(docs, nameof(docs));
                Argument.Ensure(docs.All(d => d != null), "Collection must not contain null elements.", nameof(docs));

                var result = await _handle.InsertMany(docs.ToNativeJson());

                return(result.GetValue <InsertManyResult>());
            }