Cosmos DB query MIN function to get the smallest id

367 views Asked by At

I have a collection of documents. I would like to find document with smallest id. I tried to run the query:

SELECT min(c.id) FROM c

But it returns an error. enter image description here The Microsoft Azure Storage Explorer does not allow to copy this text, therefore i pasted an image. How to return the smallest id?

1

There are 1 answers

1
DSpirit On BEST ANSWER

Whenever you want to access a value only, use the VALUE keyword as follows:

SELECT VALUE min(c.id) FROM c

Especially when it comes to cross-partition queries this is required, as else the request would fail.