我下面用它们的确切结构likes例如.numChildren()总是返回0
,但出于不同的目的:
/functions-project-12345
/db
/1
contacts_count: 0
/contacts
1: true
2: true
3: true
CONTACTS_COUNT得到在正确的位置创建的,虽然由于某些原因,CONTACTS_COUNT保持返回0
exports.contactsCount = functions.database.ref('/db/{userid}/contacts').onWrite(event => {
return event.data.ref.parent.child('contacts_count').set(event.data.numChildren());
});
我也尝试在/ db/{userid}/contacts/{id}处设置触发器,并且在读完所有文档后,仍然无法使其返回正确的计数。
事实上,具有完全相同的结构,在喜欢例如:
/functions-project-12345
/posts
/key-123456
likes_count: 32
/likes
user123456: true
user456789: true
user786245: true
和在服务器上运行:
exports.countlikes = functions.database.ref('/posts/{postid}/likes').onWrite(event => {
return event.data.ref.parent.child('likes_count').set(event.data.numChildren());
});
仍然保存成likes_count
是event.data
中的event.data.numChildren()
对/ db/{的引用rid}/contacts节点,对吗?
嗨,我也有同样的结果。 –