[英]Firebase - update() value in database
I'm trying to update()
a value inside of my firebase database, but I'm struggling. 我正在尝试在我的Firebase数据库中update()
一个值,但是我很挣扎。
I first did: 我首先做了:
this.database.list('/replies/'+this.postData.parent+'/'+this.postData.id).update('score', this.voteCount)
Thinking that would work, but I got an error: 认为这可行,但出现错误:
ERROR Error: Reference.update failed: First argument must be an object containing the children to replace. 错误错误:Reference.update失败:第一个参数必须是包含要替换的子代的对象。
I then tried: 然后,我尝试:
this.database.list('/replies/'+this.postData.parent+'/'+this.postData.id).update({'score': this.voteCount})
with this.voteCount
being an integer. 其中this.voteCount
为整数。
and I got the following error: 我收到以下错误:
ERROR Error: Expects a string, snapshot, or reference. 错误错误:需要一个字符串,快照或引用。 Got: object 得到:对象
I'm really confused as to why it's first asking for an object and then later tells me it doesn't want an object.. 我真的很困惑为什么它首先要一个对象,然后告诉我它不想要一个对象。
If I change update()
to set()
and keep it as ('score', this.voteCount)
it works fine, but I don't want to set it, I want to update it if it exists.. 如果我将update()
更改为set()
并将其保留为('score', this.voteCount)
它可以正常工作,但是我不想设置它,如果它存在,我想对其进行更新。
Am I doing something wrong? 难道我做错了什么? Thank you! 谢谢!
尝试:
this.database.ref('/replies/'+this.postData.parent+'/'+this.postData.id).update({'score': this.voteCount})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.