admin管理员组文章数量:1300041
I know how to write the server timestamp to Firestore as a date string:
doc_ref.set({ts: firebase.firestore.FieldValue.serverTimestamp()});
but how can I store its unix timestamp as a number instead? Is this even possible? I need to be able to mirror a subset of my Firestore documents in Algolia and I don't believe I can sort an Algolia index by timestamp strings.
I know how to write the server timestamp to Firestore as a date string:
doc_ref.set({ts: firebase.firestore.FieldValue.serverTimestamp()});
but how can I store its unix timestamp as a number instead? Is this even possible? I need to be able to mirror a subset of my Firestore documents in Algolia and I don't believe I can sort an Algolia index by timestamp strings.
Share asked Dec 31, 2017 at 4:31 VincentVincent 1,6511 gold badge12 silver badges24 bronze badges1 Answer
Reset to default 10It's not being stored as a string in the document - that's just how it serverTimestamp renders in the console. If you examine the ts field more closely, you'll see that it has a type of "timestamp". When you go to edit the value in the console by clicking it, you'll see the type a value clearly shown as a date type. When you read it back out (in JavaScript), you'll get a Date object back, and you can get the unix epoch-based time from that.
本文标签: javascripthow to write server timestamp in milliseconds to FirestoreStack Overflow
版权声明:本文标题:javascript - how to write server timestamp in milliseconds to Firestore - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741614809a2388465.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论