Firebase - 在对多个节点进行更新/扇出时设置优先级 [英] Firebase - set priority when doing an update/fanout to several nodes

查看:158
本文介绍了Firebase - 在对多个节点进行更新/扇出时设置优先级的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在一次更新中写入Firebase数据库的多个部分/节点。这样做时可以设置节点的优先级吗?例子:

pre $ firebaseRef.update(
/ some / node /:value,
/ some / other / node:other value
])

如果我想同时在/ some / other / node设置节点的优先级。那可能吗?例如:

  firebaseRef.update([
/ some / node /:value,
/ some / other / node:{
value:other value,
priority:0 - Date.now()
}
])


解决方案

你几乎知道了,magic属性被命名为 .priority

  firebaseRef.update([
/ some / node /:value,
/ some / other / node:{
value:other value,
.priority:0 - Date.now()




$ b $ p $注意到并没有太多的原因(如reversedTimestamp:0 - Date.now())将会完成相同的操作,隐藏/魔法也会减少。


更新



看来你想要更新节点的值,而不是一个名为value的子节点。 (原始)价值和优先权,使用:

pre $ firebaseRef.update(
/ some / node /:value,
/ some / other / node:{
.value:other value,
.priority:0 - Date.now()
}
]);


I'm writing to several parts/nodes of my Firebase database in one update. Is it possible to set the priority of a node when doing this? Example:

firebaseRef.update([
    "/some/node/": "value",
    "/some/other/node": "other value"
])

What if I want to set the priority of the node at "/some/other/node" at the same time. Is that possible? Something like:

firebaseRef.update([
    "/some/node/": "value",
    "/some/other/node": {
        value: "other value",
        priority:  0 - Date.now()
    }
])

解决方案

You almost got it, the "magic" property is named .priority:

firebaseRef.update([
    "/some/node/": "value",
    "/some/other/node": {
        value: "other value",
        ".priority":  0 - Date.now()
    }
]

Note that there aren't really a lot of reasons to use priorities anymore in Firebase. Adding a normally named property (e.g. "reversedTimestamp": 0 - Date.now()) will accomplish the same and is less hidden/magic.

Update

It seems you want to update the node's value, not a child named value. To set the (primitive) value and priority in one go, use:

firebaseRef.update([
    "/some/node/": "value",
    "/some/other/node": {
        ".value": "other value",
        ".priority":  0 - Date.now()
    }
]);

这篇关于Firebase - 在对多个节点进行更新/扇出时设置优先级的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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