Must contain at least 1 request. (Parameter 'requests')

158 Points
49 Posts

I'm try to update record in bulk in mongoDB collection but getting following error:

System.ArgumentException: Must contain at least 1 request.

Not sure what is reason of this error.

Views: 87
Total Answered: 1
Total Marked As Answer: 0
Posted On: 27-Oct-2020 22:56

Share:   fb twitter linkedin
534 Points
132 Posts

It's an error to call BulkWrite with an empty list of requests, and BulkWrite will throw an exception if it is called with an empty list. You can easily replicate it using  following code:

var requests = Enumerable.Empty<WriteModel<C>>();

It will throw following run time exception:

System.ArgumentException: Must contain at least 1 request.
Parameter name: requests
   at MongoDB.Driver.MongoCollectionImpl`1.BulkWrite(IEnumerable`1 requests, BulkWriteOptions options, CancellationToken cancellationToken) in C:\work\rstam\mongo-csharp-driver\src\MongoDB.Driver\MongoCollectionImpl.cs:line 151
   at TestCSharp1956.Program.Main(String[] args) in C:\projects\TestCSharp1956\TestCSharp1956\Program.cs:line 27
Posted On: 14-Nov-2020 23:22
 Log In to Chat