我想将我的Cloud Firestore与Algolia搜索索引同步。我目前只能部署firestore函数,但它不会触发onWrite或onChange。我遵循这个指南:Angular Full Text Search With Algolia Backend
正如您所看到的,JS已经部署,但是当我在数据库中添加、删除或更改文档时,它不会触发。日志也没有显示出来。
数据库设计:
-|search
-|searchId
-|id: string
-|name: sting
-|ref: string数据库规则:
//Search field
match /search/{searchId}{
allow read;
allow write: if request.auth != null;
}JS函数:
const functions = require('firebase-functions');
const admin = require("firebase-admin");
admin.initializeApp(functions.config().firebase);
const algoliasearch = require('algoliasearch');
const algolia = algoliasearch(functions.config().algolia.appid, functions.config().algolia.adminkey);
exports.updateIndex = functions.database.ref('/search/{searchId}').onWrite(event => {
const index = algolia.initIndex('search');
const searchId = event.params.searchId
const data = event.data.val()
if (!data) {
return index.deleteObject(searchId, (err) => {
if (err) throw err
console.log('Search Removed from Algolia Index', searchId)
})
}
data['objectID'] = searchId
return index.saveObject(data, (err, content) => {
if (err) throw err
console.log('Search Updated in Algolia Index', data.objectID)
})
});

发布于 2018-03-25 04:42:26
我也面临着类似的问题。更改这些行:
exports.updateIndex = functions.database.ref('/search/{searchId}')...
至
exports.updateIndex = functions.firestore.document('search/{searchId}')...
和
const data = event.data.val()
至
const data = event.data.exists ? event.data.data() : null;
它应该是有效的。它对我很有效,但我现在要面对
Function returned undefined, expected Promise or value日志错误,不能解决它,但函数工作。
https://stackoverflow.com/questions/49287841
复制相似问题