Anione good in firebase?

addcomment(val){

this.x.push(val);
let  newdate= Date()
this.collection.push(val);

}
as can see when sending function calling it.
it creates an object with element value in it in firebase,
a comment with a unique primary id .
Then when i want to read the comments
I need create an observable with async pipe.
but its not ordered like latest first its a random order on all messages how can i fix this?

Sequential or Guid? Does the data have a timestamp?

There’s a lot missing here when it comes to reading the values back. Namely if you want them ordered you need to save your val with the date/time/timestamp to order them when you put them in. Firebase doesn’t keep track of the order you put items into its database, as the database model is essentially a “hashmap”.(yes its more complicated than that, but for this example it can be considered as such) A key thing about a hashmap datastructure is the data is essentially unordered.

So to re-read the values “out of firebase” you will need to put them in with information to have them ordered. For example, assuming your val is an object you can do something like this:

  addComment(value) {
  value.createdDate = new Date();
  this.collection.push(value);
}

And to read values out with an async pipe using Angularfire2 (assuming that is what you use, ONLY because you mention async pipe, which is an Angular feature)

getComments(): Observable<Array<any>> {
  return this.collection('comments').valueChanges();
}

Beyond the simple examples I gave you will probably need to understand how Observables work in general (rxjs) Angular works with Observables (such as what the async pipe does) generally how firebase+firestore works and how the angularfire2 lib works.

I must state again, I provided most of my input assuming your using Angular with the angularfire2 package, the general idea ob observables still applies if you aren’t but the fact you mentioned async pipe, I assume Angular.

I tried you sollution but in angular the object i make like so say i make
let f be an object typescript complains i cant push the object.th.at is not assignable to type
any,like an argument?? im using angularfirbaselist observable i think is its name.
But however if i ignore the error
the function actually pushes an object in to the list but in getcomments
onli show [object:object]
How to make it work what is next step.

Argument of type ‘{ value: any; createdDate: Date; message: any; }’ is not assignable to parameter of type ‘any[]’.
Property ‘includes’ is missing in type ‘{ value: any; createdDate: Date; message: any; }’

this is the full error message i mangage to add the object to the list aniway but need to fix this error
and date is not adding at all just doesnt show in firebase.

i partially solved the eroor the only thing left is why date() is not saved in database…object works
perfect thanaks anihow