Firestore实时监听器相当于“Child_Added”

时间:2018-03-01 00:29:24

标签: firebase google-cloud-firestore

我正在尝试为Firestore实时监听器找出解决方案。我知道你可以听取更改,并在onSnapshot上查看添加,删除,更改的内容......但是有没有办法只是听取添加内容?

我不喜欢当数据发生变化或者添加新文档时,查询会检索每一条数据。感觉就像无法进行数据传输...特别是如果您正在使用应用程序3G网络

这是一个合理的担忧吗?或者查询返回的数据可忽略不计?我只想获得集合的“新”增加

1 个答案:

答案 0 :(得分:0)

您尝试过吗?

exports.createUser = functions.firestore
.document('users/{userId}')
.onCreate((snap, context) => {
  // Get an object representing the document
  // e.g. {'name': 'Marie', 'age': 66}
  const newValue = snap.data();

  // access a particular field as you would any JS property
  const name = newValue.name;

  // perform desired operations ...
});