Firebase REST API-POST请求
我正在尝试将记录添加到Firebase数据库,如下所示: 所以基本上我们有Firebase REST API-POST请求,rest,firebase,post,firebase-realtime-database,Rest,Firebase,Post,Firebase Realtime Database,我正在尝试将记录添加到Firebase数据库,如下所示: 所以基本上我们有匹配项->用户提供的\u id->{id,location} 这可以通过使用以下代码和Swift API实现: let matches = Database.database().reference().child("users").child(UserDefaults.standard.object(forKey: "uid") as! String).child("matches").child((all_listi
匹配项
->用户提供的\u id
->{id,location}
这可以通过使用以下代码和Swift API实现:
let matches = Database.database().reference().child("users").child(UserDefaults.standard.object(forKey: "uid") as! String).child("matches").child((all_listings?[index].listingId)!)
let newBookData = [
"id": all_listings?[index].listingId,
"location" : all_listings?[index].location
] as [String : Any]
matches.setValue(newBookData)
我现在尝试使用Firebase REST API复制此行为。我基本上是向地址发送一个POST
请求:
https://PROJECTID.firebaseio.com/.../matches/-LOpJmU9yj4hAocHjnrB.json
使用以下数据:
"{\"id\":\"-LOpJmU9yj4hAocHjnrB\",\"location\":\"Edinburgh\"}"
但是,这会导致以下结果:
如您所见,在将元素添加到数据库之前,它会创建额外的ID和嵌套级别。如何修复此问题?不要使用POST。根据报告: 要实现JavaScript push()方法的等效功能(请参见数据列表),可以发出POST请求 你不想被推到这里。推送操作将创建一个新的随机推送ID,并将其作为您提供的数据的键
如果您已经知道要设置的位置(看起来您已经有了已知的推送id),只需使用PUT在该位置设置数据。谢谢您的帮助!关于这个问题的前一个版本,我删除
F#
代码和标记的原因主要是因为我觉得这会让潜在的回答者感到厌烦,因为他们不熟悉F#
,而这个问题本身与F#
没有什么关系,因为一旦我知道请求需要什么样子,我就知道如何在F#
中实现这一点。