1

How can I write the serverValue.timestamp() as a separate child in Firebase?
I want to be able to write something like this:

-Country
---Location
------serverValue.timestamp()
---------Name: Peter
---------Age: 30
---------Class: Physics

When I try this it fails:

self.ref?.child(country).child(location).child(serverValue.timestamp()).updateChildValues(["Name:" : name, "Age:" : age, "Class:" : class])    

I can't seem to get it right...

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
PerNil
  • 187
  • 1
  • 11

1 Answers1

1

According to the docs timeStamp is a placeholder for a value in which the database recognize and put in the current servertime. This does not apply for Strings in the database. Strings in the databases are names for folders, documents, collections, keys etc. So the method you are calling only works for a value in combination with a key, for storing data in JSON format.

If you REALLY want to use the current timestamp without users faking the current time, I think the only thing you can do is:

  1. write the data to a temp folder
  2. trigger a Cloud Function that listens to that folder/document
  3. write the data back to your preferred folder/document, while the name of the folder/document is Date.now() (function in javascript)

Else you could always use Swift's current timestamp: How to get 18-digit current timestamp in Swift?

Community
  • 1
  • 1
J. Doe
  • 12,159
  • 9
  • 60
  • 114