小编Saa*_*sad的帖子

如何使用云功能在firestore中输入数据?

对于文档 {userID},我想创建一个名为“notfications”的子集合并将数据设置为它。如何访问文档和设置数据?

const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);

exports.updateUser = functions.firestore
.document('users/{userID}/reports/{reportID}')
.onUpdate((change, context) => {
  // Get an object representing the document
  // e.g. {'name': 'Marie', 'age': 66}
  const newValue = change.after.data();
  // ...or the previous value before this update
  const previousValue = change.before.data();

  // access a particular field as you would any JS property
    const st1 = newValue.status;
   const st2 = previousValue.status;
   console.log('I am a log entry!' + st1 + " " + st2);
   // …
Run Code Online (Sandbox Code Playgroud)

node.js firebase google-cloud-functions google-cloud-firestore

2
推荐指数
1
解决办法
4743
查看次数

0
推荐指数
1
解决办法
2223
查看次数