Get last created document in a Firebase Firestore

2019-08-25 02:42发布

Is there any way to get last created document in Firebase Firestore collection? My requirement is when user signed I have to add a document in a collection named 'history'; When the user signed out I want to update that document with a field called 'signout'; So if i get the lastly added document it is very easy to update. Is there any way to do this?

1条回答
Viruses.
2楼-- · 2019-08-25 03:08

Is there any way to get last created document in firebase firestore collection?

Yes, there is! The simplest way to achieve this is to add a Date property to each object in your collection, then simply query it according to this new property descending and call limit(1) function. That's it!

查看更多
登录 后发表回答