I\'m trying to get the timestamp of a document that I created in firestore, but what I get is this:
myService.ts
getDomiciliari
I think you are using FieldValue.serverTimestamp()
the wrong way: as the documentation states, firebase.firestore.FieldValue
methods return "values that can be used when writing document fields with set() or update()".
(See https://firebase.google.com/docs/reference/js/firebase.firestore.FieldValue)
You are using the serverTimestamp()
method while reading the data.
You should use it when you create the records in the database, as you mention at the end of your question.
EDIT: Do as follow:
const timestamp = firebase.firestore.FieldValue.serverTimestamp();
docRef.update({ updatedAt: timestamp });
You can then query like
collectionRef.orderBy('updatedAt').get()
.then(snapshot => {
snapshot.forEach(doc => {
...
});
})
.catch(err => {
console.log('Error getting documents', err);
});
The above code is pure JavaScript and you may adapt it to angular and type script but the philosophy is the same.