firestore-backup-restore icon indicating copy to clipboard operation
firestore-backup-restore copied to clipboard

Timestamp field fails to import nanoseconds

Open drmencos opened this issue 3 years ago • 3 comments

Hello!

I'm trying to import a date field with nanoseconds, the problem is, when I query the data from Firestore I always get 0 nanoseconds.

I'm using v1.1.0. My client is in Angular Fire v7.3.0.

This is my json data:

{
  "mycollection": [
    {
      "date": {
        "_seconds": 1598507986,
        "_nanoseconds": 660000000
      }
    }
  ]
}

The response:

date: at {seconds: 1598507986, nanoseconds: 0}

I tried using dates: ['date'] and autoParseDates: true. Both ways the dates are parsed ok, and they're displayed correctly in Firebase Console, but since it won't show nanoseconds, I can't tell if they are being imported ok.

Am I doing something wrong, or does it have to do with the client?

drmencos avatar Jun 03 '22 21:06 drmencos

Ok, is not the client. I manually added the document and the client responded with the correct nanoseconds value.

drmencos avatar Jun 10 '22 22:06 drmencos

@drmencos how did you try with the client?

dalenguyen avatar Jun 15 '22 16:06 dalenguyen

@dalenguyen, thanks for your answer. I converted the date object to a Timestamp before sending the document:

myDocument.date = new Timestamp(myDocument.date._seconds, myDocument.date._nanoseconds);
addDoc(collection(db, 'mycollection'), myDocument);

drmencos avatar Jun 20 '22 19:06 drmencos