Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/39.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 云函数:HTTP触发不一致的批提交_Javascript_Node.js_Firebase_Google Cloud Functions_Google Cloud Firestore - Fatal编程技术网

Javascript 云函数:HTTP触发不一致的批提交

Javascript 云函数:HTTP触发不一致的批提交,javascript,node.js,firebase,google-cloud-functions,google-cloud-firestore,Javascript,Node.js,Firebase,Google Cloud Functions,Google Cloud Firestore,我正试图通过HTTP请求触发Google cloud函数来更新Firestore和RTDB中的多个集合,我已经做了几次测试,但批量提交有时会起作用。我还尝试运行测试,从代码中排除RTDB更新,但没有什么变化 如果出现问题,我会收到以下错误消息,状态代码为500 错误:无法修改已提交的写回 下面是示例代码: 服务器端代码 客户端代码 详细信息中的错误消息 也许我的代码遗漏了什么?我解决了问题。我犯了一个愚蠢的错误 我必须在app.post中声明批处理 反而 module.exports = ({

我正试图通过HTTP请求触发Google cloud函数来更新Firestore和RTDB中的多个集合,我已经做了几次测试,但批量提交有时会起作用。我还尝试运行测试,从代码中排除RTDB更新,但没有什么变化

如果出现问题,我会收到以下错误消息,状态代码为500

错误:无法修改已提交的写回

下面是示例代码:

服务器端代码

客户端代码

详细信息中的错误消息


也许我的代码遗漏了什么?

我解决了问题。我犯了一个愚蠢的错误

我必须在app.post中声明批处理

反而

module.exports = ({ admin, cors, express, functions }) => {
  const app = express();
  const fireStore = admin.firestore();
  const rtdb = admin.database();
  const apps = fireStore.collection('apps');
  const users = fireStore.collection('users');
  const batch = admin.firestore().batch();
};
也许在post中创建批处理对象就足够了?否则,每次发布到/发生时,您将创建管理员、数据库、批处理等。。。
const data = {
      activityState: {
        currentActiveStatus: "online",
        usingApp: "true"
      },
      user: {
        displayName: this.displayName,
        photoURL: this.photoURL,
        currentActiveStatus: "online",
        emailVerified: "true"
      }
    };
    this.userService.updateUserProfile(this.displayName, this.photoURL).then((accessToken) => {
      const url = 'https://us-central1/dbname/cloudfunctions.net/functionname';
      this.http.post(url, JSON.stringify(data), {
        headers: {'Authorization': accessToken, 'Content-Type': 'application/json; charset=utf-8'}
      }).subscribe((res) => {
        // Worked well
      }, (err) => {
        // Went wrong
      });
    });
Error: Cannot modify a WriteBatch that has been committed.  
    at WriteBatch.verifyNotCommitted (/user_code/node_modules/firebase-admin/node_modules/@google-cloud/firestore/src/write-batch.js:148:13)  
    at WriteBatch.update (/user_code/node_modules/firebase-admin/node_modules/@google-cloud/firestore/src/write-batch.js:333:10)  
    at app.post (/user_code/exports/auth/user/startapp/initDefaultState.f.js:54:11)  
    at Layer.handle [as handle_request] (/user_code/node_modules/express/lib/router/layer.js:95:5)  
    at next (/user_code/node_modules/express/lib/router/route.js:137:13)  
    at Route.dispatch (/user_code/node_modules/express/lib/router/route.js:112:3)  
    at Layer.handle [as handle_request] (/user_code/node_modules/express/lib/router/layer.js:95:5)  
    at /user_code/node_modules/express/lib/router/index.js:281:22  
    at Function.process_params (/user_code/node_modules/express/lib/router/index.js:335:12)  
    at next (/user_code/node_modules/express/lib/router/index.js:275:10)
app.post('/', (req, res) => {
    const batch = admin.firestore().batch();
});
module.exports = ({ admin, cors, express, functions }) => {
  const app = express();
  const fireStore = admin.firestore();
  const rtdb = admin.database();
  const apps = fireStore.collection('apps');
  const users = fireStore.collection('users');
  const batch = admin.firestore().batch();
};