3

I have a Cosmos DB query that is intermittently consuming very high amounts of RUs. In most cases, the Request Charge is around 1000 RUs, but in others it is as high as 80,000 RUs. I am using the Mongo API for Cosmos DB and using the Node.js Mongo Driver to query the DB.

This is the query with some of the field names changed:

const query = {
        state: 'FOO',
        startDate: { $lt: new Date() },
        $or: [
            { takeActionOn: null },
            { takeActionOn: { $lt: new Date() } }
        ]
}

db.collection(collectionName)
    .find(query)
    .limit(250);

All the fields in the query are indexed, but the Partition Key is not included. I've been investigating the issue using the Cosmos DB command "getLastRequestStatistics". The response from that command contains CommandName, RequestCharge, and a few other pieces of metadata.

I found that in the cases where the RU cost was low, the CommandName returned from getLastRequestStatistics was "find", whereas in the cases where RU cost was high, the CommandName was getMore. I found this documentation on why/when getMore is used by MongoDB Server under the hood, but have not been able to find precisely why it is only being used in some cases.

This leads to my questions:

  • Under what conditions would getMore be used?
  • How can I modify my query to lower RU cost and avoid using getMore? (Would setting a batchSize option help here?)
mairf
  • 51
  • 5

0 Answers0