检查大于1的孩子的数量 [英] Check if number of children greater than 1
问题描述
如何检查Firebase云端函数中某个节点的子项数是否大于1?在我的情况下,我想看看如果天数是> 1
例如:
if('message'node的子节点> 1)
//做某事
例如:
$ b 其中检索消息
对象并计算键,例如
var x = {1:1,A:2};
Object.keys(x).length; //输出2
更有利的是, code> count 节点作为 三即可。您还可以使用 示例: How do I check if the number of children of a node is greater than 1 in Cloud Functions for Firebase? In my case I want to see if the number of days is > 1 For example: Three Options, depending on your use case: One. Retrieve the Two. More favorable, keep a Three. You can also use Example:
这篇关于检查大于1的孩子的数量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!消息
的子节点,并在添加和删除子节点时进行监视。 Firebase提供了一个如何实现的例子: -count / functions / index.jsrel =nofollow noreferrer>这里
numChildren()
作为快照的顶层。 numChildren
//如果删除了喜欢的数字,请重新计算喜欢的数量
exports.countDays = functions。 onWrite(event => {
const theRef = event.data.ref;
const collectionRef = theRef.parent.child('days'); $ b (messageData.numChildren())> 1){
//做某事
}
})
});
if(children of 'messages' node > 1)
// do something
messages
object and count the keys, e.g.var x = {"1":1, "A":2};
Object.keys(x).length; //outputs 2
count
node as a child of messages
and monitor when children are added and deleted. Firebase has provided an example on how to do that:
numChildren()
for the top level of the snapshot.// If the number of likes gets deleted, recount the number of likes
exports.countDays = functions.database.ref('/messages').onWrite(event => {
const theRef = event.data.ref;
const collectionRef = theRef.parent.child('days');
collectionRef.once('value').then(messagesData => {
if(messagesData.numChildren()) > 1) {
// do something
}
})
});