Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

SOLVED: Firestore onsnapshot

hesham:

I am making a chat with Jquery and Firestore, and everything works, but i am trying to get only the last 10 messages in the database.

I have a collection "chat" and inside, i have the documents with Generated Ids from firestore.

I am using this function:


firestore.collection("chat").orderBy("date", "desc").limit(10).onSnapshot(function(snapshot) {

snapshot.forEach(function(doc) {}

and in the foreach, i am appending my HTML, i got the messages ordered by date without any issues, but i don't know how to get the last 10 messages for examples as the documented has generated IDs "can't filter by id".

Update: Now it's sorting and getting the last 10 messages by order("date","desc"), but as in the screenshot, the last messages go up not down!

chat view



Posted in S.E.F
via StackOverflow & StackExchange Atomic Web Robots
This Question have been answered
HERE


This post first appeared on Stack Solved, please read the originial post: here

Share the post

SOLVED: Firestore onsnapshot

×

Subscribe to Stack Solved

Get updates delivered right to your inbox!

Thank you for your subscription

×