在Firebase中将serverValue.timestamp写入子级 [英] Write serverValue.timestamp as child in Firebase

查看:52
本文介绍了在Firebase中将serverValue.timestamp写入子级的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在Firebase中将serverValue.timestamp()作为单独的子代编写?
我希望能够编写如下内容:

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

-国家
---位置
------ serverValue.timestamp()
---------名称:彼得
---------年龄:30
---------课程:物理

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

当我尝试它失败时:

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

我似乎无法正确理解...

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

推荐答案

根据

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. 将数据写入临时文件夹
  2. 触发可监听该文件夹/文档的Cloud Function
  3. 将数据写回到您的首选文件夹/文档中,而文件夹/文档的名称为Date.now()(javascript中的功能)
  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)

否则,您始终可以使用Swift的当前时间戳:如何在Swift中获得18位的当前时间戳?

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

这篇关于在Firebase中将serverValue.timestamp写入子级的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆