简体   繁体   English

如果不知道其密钥,如何在Firebase中更新节点?

[英]How to update a node in Firebase if I don't know its key?

In my Firebase DB, I have a list of nodes with auto-generated keys. 在我的Firebase数据库中,我有一个带有自动生成键的节点列表。

"visitors" : {
"-KTmRYgWJkT2nq4i1S1D" : {
  "firstname" : "Jsdfa",
  "lastname" : "Jsdfa",
  "visitorId" : "123"
},
"-KTnUbLCtvdeA6G4p5Xh" : {
  "firstname" : "Jsdfadf",
  "lastname" : "Jfasdgf",
  "visitorId" : "124"
},
"-KToFT1rWLuw6ZbS_xGU" : {
  "firstname" : "Jdfadfa",
  "lastname" : "Jsdfad",
  "visitorId" : "125"
}
}

Firstly, I found a node that needs to be updated, to do this I used following code: 首先,我找到了一个需要更新的节点,为此,我使用了以下代码:

[[_ref child:@"visitors"] queryOrderedByChild:@"visitorId"] queryEqualToValue:@(visitorId)]

And then I need to update it or just delete it. 然后,我需要对其进行更新或将其删除。 Firebase documentation says that to do this, I need to have a node key. Firebase文档说,要做到这一点,我需要有一个节点密钥。

And that is the problem. 这就是问题所在。 I have tried to find a way how to fetch this key, but without any success, I can't find any information about it. 我试图找到一种方法来获取此密钥,但是没有成功,我找不到任何有关它的信息。 Can anyone help me to solve this issue? 谁能帮我解决这个问题? Any help would be highly appreciated. 任何帮助将不胜感激。

The 'visitorId' that you have is the required Node Key. 您拥有的“ visitorId”是必需的节点密钥。

To delete this node, use: 要删除此节点,请使用:

[[[_ref child:@"visitors"] child:@(visitorId)] removeValue];

To update this node, use: 要更新此节点,请使用:

 [[[_ref child:@"visitors"] child:@(visitorId)] updateChildValues:(dictionary)];

Here, dictionary is a nonnull NSDictionary type, you can pass your values to update in this object as a key-value pair. 在这里,dictionary是非null的NSDictionary类型,您可以将值作为键值对传递给此对象以进行更新。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Firebase - 当您不知道父键的值时访问子节​​点 - 由childByAutoId()生成 - Firebase - accessing child node when you don't know the value of the parent key - generated by childByAutoId() 当我所有的节点都在本地声明时,不知道如何更新分数标签节点 - don't know how to update the score label node , when all my nodes are declared locally 我不知道如何将弹出框与按钮对齐 - I don't know how to align my popovers to button 我不知道如何在Swift中将屏幕截图发送到Instagram应用程序 - I don't know how to send screenshot to Instagram application in Swift Firebase如果我不认识两个孩子的ID不明,请访问他们的孩子 - Firebase Access a children if I don't know two childs who have unknown ids 我不了解并且不知道如何解决的ImagePicker IOS错误 - ImagePicker IOS errors i don't understand and don't know how to fix 不要将所有文本字段更新为 firebase - Don't update all textfields to firebase Xcode中的致命错误-我知道原因,但不知道如何解决 - Fatal error in Xcode - I know the cause but don't know how to fix it 一个简单的代码,不知道如何调试 - A simple code, don't know how to debug 当我不知道会有多少节时,如何重新加载UITableView的数据? - How do I reload a UITableView's data when I don't know how many sections there will be?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM