When running the code below I get the first item not the last. Why is that?
async def example():
db: google.cloud.firestore.AsyncClient = AsyncClient()
await db.document("1/1").set({"a": "1"})
await db.document("1/2").set({"a": "2"})
last = (
await (
db.collection("1")
.order_by("a")
.limit_to_last(1) # <= not working - getting the first not last
.get()
)
)[0].to_dict()
first = (
await (
db.collection("1")
.order_by("a")
.limit(1)
.get()
)
)[0].to_dict()
print(first, last) # {'a': '1'} {'a': '1'}
asyncio.run(example())
The workaround is the use of descending ordering with limit()
. But I don't understand - what is the purpose of the limit_to_last()
function?