部署集合名称中带有空格的Firestore功能时出错 [英] Error Deploying Firestore Function with a space in the name of a collection

查看:50
本文介绍了部署集合名称中带有空格的Firestore功能时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试部署一个云功能,以便在我的Firestore中创建新文档时更新Algolia搜索索引.一切似乎都很好地开始,但是到最后,它出错了.我已经看过文档,感觉语法是正确的,所以我不确定此时该怎么做. Cloud Functions日志没有指向任何内容,只是回显了我在下面收到的错误

I'm trying to deploy a cloud function that updates an Algolia Search index whenever a new document is created in my Firestore. Everything seems to start well but then at the very end, it errors out. I've been through the docs and it feels like my syntax is correct so I'm not sure what to do at this point. The Cloud Functions log don't point to anything and just echo the error that I received below

错误消息:

=== Deploying to 'test-ffdbb'...

i  deploying functions
i  functions: ensuring necessary APIs are enabled...
i  runtimeconfig: ensuring necessary APIs are enabled...
+  runtimeconfig: all necessary APIs are enabled
+  functions: all necessary APIs are enabled
i  functions: preparing functions directory for uploading...
i  functions: packaged functions (1.25 KB) for uploading
+  functions: functions folder uploaded successfully
i  functions: updating function onProductCreated...
!  functions[onProductCreated]: Deployment error.
Failed to configure trigger providers/cloud.firestore/eventTypes/document.create@firestore.googleapis.com (onProductCreated)

我的代码:

const functions = require('firebase-functions');
const algoliasearch = require('algoliasearch');

// App ID and API Key are stored in functions config variables
const ALGOLIA_ID = functions.config().algolia.app_id;
const ALGOLIA_ADMIN_KEY = functions.config().algolia.api_key;

const ALGOLIA_INDEX_NAME = "Firestore";
const client = algoliasearch(ALGOLIA_ID, ALGOLIA_ADMIN_KEY);

// Update the search index every time a blog post is written.
exports.onProductCreated = functions.firestore
.document("Product Catalog/{id}")
.onCreate(event => {
  const product = event.data.data();
  product.objectID = event.params.postId;

  const index = client.initIndex(ALGOLIA_INDEX_NAME);
  return index.saveObject(product);
});

package.json :

{
  "name": "functions",
  "description": "Cloud Functions for Firebase",
  "scripts": {
    "serve": "firebase serve --only functions",
    "shell": "firebase experimental:functions:shell",
    "start": "npm run shell",
    "deploy": "firebase deploy --only functions",
    "logs": "firebase functions:log"
  },
  "dependencies": {
    "@google-cloud/firestore": "^0.8.2",
    "algoliasearch": "^3.24.5",
    "firebase-admin": "~5.4.2",
    "firebase-functions": "^0.7.1"
  },
  "private": true
}

推荐答案

问题似乎出在路径段Product Catalog中的空格.当我删除它时,该功能成功部署:

The problem appears to be the space in path segment Product Catalog. When I remove it, the function deploys successfully:

exports.onProductCreated = functions.firestore
  .document("ProductCatalog/{id}") // <== space removed
  .onCreate(event => {...});

还请注意,路径中的通配符为id,而您引用的代码中的通配符为postId:

Also note that the wildcard in your path is id and in the code you reference postId:

  product.objectID = event.params.postId;

这篇关于部署集合名称中带有空格的Firestore功能时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆