首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >algolia firestore函数不会触发

algolia firestore函数不会触发
EN

Stack Overflow用户
提问于 2018-03-15 05:23:43
回答 1查看 233关注 0票数 0

我想将我的Cloud Firestore与Algolia搜索索引同步。我目前只能部署firestore函数,但它不会触发onWrite或onChange。我遵循这个指南:Angular Full Text Search With Algolia Backend

正如您所看到的,JS已经部署,但是当我在数据库中添加、删除或更改文档时,它不会触发。日志也没有显示出来。

数据库设计:

代码语言:javascript
复制
-|search
    -|searchId
        -|id: string
        -|name: sting
        -|ref: string

数据库规则:

代码语言:javascript
复制
//Search field
match /search/{searchId}{
    allow read;
  allow write: if request.auth != null;
}

JS函数:

代码语言:javascript
复制
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)
  })

});

EN

回答 1

Stack Overflow用户

发布于 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日志错误,不能解决它,但函数工作。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49287841

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档