Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it normal for timestamp to be saved into Firestore as "timestamp"?

I am saving server value timestamp as follow:

let data : [String: Any] = ["userId": 9,
                            "name": "Elon Musk",
                            "timeCreated": ServerValue.timestamp()]

 let doc = firestore.collection("orders").document()
 doc.setData(data){ (error) in

 }

When looking into Firestore, though I see this:

enter image description here

Is this normal? Shouldn't there be instead a long containing the number of milliseconds since the Unix Epoch?

like image 253
rgoncalv Avatar asked Jan 12 '18 21:01

rgoncalv


Video Answer


1 Answers

You're using the Realtime Database notion of server timestamp, which is ServerValue.timestamp. It's essentially a dictionary with the values you showed: {'.sv': 'timestamp'}. That's not compatible with Firestore.

Instead, you want to use Firestore's notion of server timestamp, which is FieldValue.serverTimestamp(). Also see the very last sample in the documentation here.

like image 108
Doug Stevenson Avatar answered Oct 09 '22 16:10

Doug Stevenson