我下面用它們的確切結構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節點,對嗎?
嗨,我也有同樣的結果。 –