Reputation: 509
I'm trying to use Algolia with Firebase Functions, but I get this error TypeError: Cannot read property 'exists' of undefined at Object.syncAlgoliaWithFirebase (/workspace/node_modules/algolia-firebase-functions/dist/index.js:79:23) I followed the steps on the npm algolia-firebase-functions library (https://www.npmjs.com/package/algolia-firebase-functions).
This is my Firebase function code:
const functions = require("firebase-functions");
const admin = require('firebase-admin')
admin.initializeApp(functions.config().firebase)
const db = admin.firestore()
const algoliasearch = require("algoliasearch");
const algoliaFunctions = require('algolia-firebase-functions');
const algolia = algoliasearch(functions.config().algolia.app,
functions.config().algolia.key);
const index = algolia.initIndex(functions.config().algolia.index);
exports.indexBesedilo = functions.firestore.document('besedila/{document}').onCreate((change, context) =>
algoliaFunctions.syncAlgoliaWithFirebase(index, change)
)
Does anyone know why I'm getting this error? Any help would be appreciated!
Upvotes: 0
Views: 404
Reputation: 7716
According to the documentation, if you're using Firebase Cloud Firestore, you should use syncAlgoliaWithFirestore
instead of syncAlgoliaWithFirebase
.
Your function becomes:
exports.indexBesedilo = functions.firestore.document('besedila/{document}').onCreate((change, context) =>
algoliaFunctions.syncAlgoliaWithFirestore(index, change)
)
Upvotes: 2