I have a file (about 1 GB) containing a JSON array with a large number of items. These items should be read in by a .NET client (using Microsoft.Azure.Cosmos
SDK v3.16.0) and created in a Cosmos DB collection using bulk execution.
Up to now, I have used CreateItemAsync
to create the items, but that requires first deserializing the file into a list of objects. Would it be faster to use the CreateItemStreamAsync
method instead? If so, how do I do that with a stream that contains an array of items? The following fails with status code RequestTimeout
, probably because the method expects the stream to contain just a single item:
await using FileStream fs = File.OpenRead(path);
ResponseMessage response = await container.CreateItemStreamAsync(fs, partitionKey);
response.EnsureSuccessStatusCode(); // fails
I suppose I have to create an individual stream for each item from the single file stream, but how without deserializing the JSON array?