Created
January 10, 2019 16:20
-
-
Save JesseE/8a3871002d742141d3b49d343dc93143 to your computer and use it in GitHub Desktop.
Firestore cloud function to update Algolia index on change
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as functions from 'firebase-functions'; | |
import * as admin from 'firebase-admin'; | |
import * as algoliasearch from 'algoliasearch'; | |
admin.initializeApp(); | |
const client = algoliasearch( | |
functions.config().algolia.app_id, | |
functions.config().algolia.api_key | |
); | |
const index = client.initIndex('movie_title'); | |
exports.updateMovies = functions.firestore | |
.document('movies/{movieId}') | |
.onUpdate((change, context) => { | |
const newData = change.after.data(); | |
const object = { | |
objectID: context.params.movieId, | |
...newData | |
} | |
return index.partialUpdateObject(object); | |
}) |
Hi, how do you add algolia info to the config object?
if you have the algolia APP ID and ADMIN API KEY. I believe I got it working by typing this in the command line:
firebase functions:config:set algolia.app_id="APP_ID" algolia.api_key="API_KEY"
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks!!