CosmosDB ReadNextAsync() functionality changed

So I found out the hard way that if you do a ReadNextAsync over a GetItemQueryIterator using the Microsoft.Azure.Cosmos library it will actually only peek to a single logical partition. Previously, Cosmos DB has taken care of this “behind the scenes”.

Now instead you have to apparently peek into all logical partitions using the feediterator like so:

The above does logical partitions X query amount of calls to cosmos (confirmed by Fiddler) and thus consumes plenty of RUs comparing to a regular partitioned query.

It seems you cannot set EnableCrossPartitionQuery anymore either on the latest SDK (I think that by doing that previously, Cosmos DB took care of spreading the query to the logical partitions in the background). Now, the queries are explicitly cross-partition unless you provide a partition key.
To me this seems like a “downgrade” from the previous, somehow it feels almost hacky how you have to iterate over several results from query.HasMoreResults and pick out something on the client side, rather than Cosmos DB taking care of splitting the queries across partitions for you. Let me know if there’s a better way to handle this.

Leave a Reply

Your email address will not be published. Required fields are marked *