简体   繁体   中英

Azure Cosmos REST API query Last n Records

I am writing a blazor wasm app using REST API to access a cosmos db database, using the cosmos db emulator for testing. I have code written for reading records, posting data and sending a SQL query.

What I am struggling to find out using the REST api, how is is possible to read the last n records, and then after that read n-skip 100 records reading backwards?

I could use x-ms-continuation header for paging records but that appears to be only available for reading data forwards.

It will be quite a few records as it is a time series db. I am looking to the REST api version of OFFSET LIMIT based on the items timestamp. Once an item is there it is never updated.

You could try using

select top <n> <field_name>

to get n items. And to make it last n items you could try

order by <collection_id>._ts desc

in your query where _ts is the timestamp when the item was stored.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM