reactjs - algolia 全文搜索,firebase
问题描述
我正在使用 firebase 样板: https ://github.com/WataruMaeda/react-firebase-boilerplate
并立即尝试添加全文搜索。
代码
import * as functions from "firebase-functions";
import * as admin from "firebase-admin";
admin.initializeApp();
const env = functions.config();
const algoliasearch = require("algoliasearch");
var client = algoliasearch(env.algolia.appid, env.algolia.apikey);
const index = client.initIndex("Moseley");
exports.indexHomecare = functions.firestore
.document("contractors")
.onCreate((snap, context) => {
const data = snap.data()
const objectId = snap.id
return index.addObject({
objectId,
...data,
})
});
exports.removeHomeCare = functions.firestore
.document("contractors")
.onDelete((snap, context) => {
const objectId = snap.id
return index.deleteObject({
objectId,
})
});
错误信息
+ functions: Finished running predeploy script.
i functions: ensuring required API cloudfunctions.googleapis.com is enabled...
i functions: ensuring required API cloudbuild.googleapis.com is enabled...
+ functions: required API cloudbuild.googleapis.com is enabled
+ functions: required API cloudfunctions.googleapis.com is enabled
i functions: preparing functions directory for uploading...
i functions: packaged functions (43.24 KB) for uploading
+ functions: functions folder uploaded successfully
i functions: uploading functions in project: indexHomecare(europe-west2), removeHomeCare(europe-west2)
i functions: creating Node.js 12 function indexHomecare(europe-west2)...
i functions: creating Node.js 12 function removeHomeCare(europe-west2)...
! functions: failed to create function removeHomeCare
HTTP Error: 400, The request has errors
! functions: failed to create function indexHomecare
HTTP Error: 400, The request has errors
Functions deploy had errors with the following functions:
indexHomecare
removeHomeCare
To try redeploying those functions, run:
firebase deploy --only "functions:indexHomecare,functions:removeHomeCare"
To continue deploying other features (such as database), run:
firebase deploy --except functions
Error: Functions did not deploy properly.
Having trouble? Try firebase [command] --help
C:\Users\pjsup\portfolio\react-firebase-boilerplate\functions>
似乎没有任何错误消息告诉我出了什么问题,我进一步密切关注了这里的 fireship 视频:https ://www.youtube.com/watch?v=3Z0V3cvgns8&ab_channel=Fireship
任何想法如何解决这一问题?
解决方案
看起来失败是由于您的功能代码中的错误。
- indexHomeCare - 要将对象添加到索引中,您必须使用 saveObject
- removeHomeCare - 要从索引中删除对象,请将对象 ID 作为字符串值传递/或在数组中进行多次删除。
exports.indexHomecare = functions.firestore
.document("contractors")
.onCreate((snap, context) => {
const data = snap.data()
const objectId = snap.id
return index.saveObject({
objectId,
...data,
})
});
exports.removeHomeCare = functions.firestore
.document("contractors")
.onDelete((snap, context) => {
const objectId = snap.id
return index.deleteObject(objectId);
});
推荐阅读
- php - PHP count 多维数组值
- jquery - 在 select2 生成的元素中传递更多属性
- python - 我的 CSV 编写器代码在字符而不是字符串之间写入分隔符
- django - 如何改变模型序列化器中的字段验证器
- sql - 模拟 FULL OUTER JOIN:LEFT+RIGHT JOIN 与交叉连接的 UNION 性能
- python - 匹配 Excel 文件中的两列并获取其他列值 - Python Pandas
- gradle - 不同源集上的不同兼容性版本
- sql-server - 如果 SQL Server 中存在数据,则标记为 2
- angular - 在 Angular 4 中调用 API 时数据丢失
- google-bigquery - BigQuery 不以毫秒为单位处理带有分区列的时间戳