如何从服务器端的Firebase数据库中检索上次创build的对象

如果这是非常简单的,我很新的Firebase云function。 我试图在我的数据库中接收最新的推送对象。 不幸的是,这个代码返回已经在'/ customers'的数据库中被推入的每个对象。 我已经尝试过了,但是那根本没有做任何事情。

exports.newCustomer = functions.database.ref('/customers/').onWrite(event => { console.log(event.data.val()); }); 

在这里输入图像说明

onWrite事件应该只捕获新的数据。 但是,也许你应该更具体这样的:

 exports.newCustomer = functions.database.ref('/customers/{randomID}').onWrite(event => { console.log(event.data.val()); //here is the data that is added console.log(event.params.randomID); // random ID console.log(event.data.val().firstName); //change firstName to anything you added. }); 

这将捕获/ customers / XXX / XXX /