A_toaster
A_toaster

Reputation: 1288

How can you get the RU/s consumed in a CosmosDB query in with pymongo?

I'm having an issue where I perform a query in the Azure portal and it consumes ~5 RU/s, but when I perform the same query in pymongo it throws "Request is Large", indicating that I don't have enough (we have 3000 RU/s provisioned).

How can I find out how many RU/s my pymongo query is consuming from within Python?

EDIT: Is there a way to find the total RU/s being used by the Cosmos (for example by other users?)

Upvotes: 1

Views: 1265

Answers (1)

Jay Gong
Jay Gong

Reputation: 23782

Use runCommand method in Pymongo:

from pymongo import MongoClient

client = MongoClient()

client = MongoClient(
    'mongodb://***@***.documents.azure.com:10255/?ssl=true&replicaSet=globaldb')
db = client.testdb
coll = db.coll
result = coll.find_one()
print(coll.find_one())

result = db.command({"getLastRequestStatistics": 1})

print("Last RU Consume:", result["RequestCharge"])

Output:

enter image description here

Got this solution from this link which is not mentioned from official document.

Upvotes: 1

Related Questions