Firebase and algolia

ERROR ALGOLIA users ADD TypeError: index.addObject is not a function
at Promise (/srv/index.js:72:8)
at tryCallTwo (/srv/node_modules/promise/lib/core.js:45:5)
at doResolve (/srv/node_modules/promise/lib/core.js:200:13)
at new Promise (/srv/node_modules/promise/lib/core.js:66:3)
at addToAlgolia (/srv/index.js:70:10)
at exports.addusersToAlgolia.functions.firestore.document.onCreate (/srv/index.js:27:12)
at cloudFunction (/srv/node_modules/firebase-functions/lib/cloud-functions.js:131:23)
at /worker/worker.js:825:24
at
at process._tickDomainCallback (internal/process/next_tick.js:229:7)

I’m getting this while I try to add from firebase to algolia. Here’s my code:

function addToAlgolia(object, indexName) {
console.log(“GETS IN addToAlgolia”);
console.log(“object”, object);
console.log(“indexName”, indexName);
const ALGOLIA_ID = functions.config().algolia.app_id;
const ALGOLIA_ADMIN_KEY = functions.config().algolia.api_key;
const client = algoliasearch(ALGOLIA_ID, ALGOLIA_ADMIN_KEY);
const index = client.initIndex(indexName);
return new Promise((resolve, reject) => {
index
.addObject(object)
.then((res) => {
console.log(“res GOOD”, res);
resolve(res);
})
.catch((err) => {
console.log(“err BAD”, err);
reject(err);
});
});
}

Hi There,

Which version of the Javascript client are you using?
On the version 4, the addObject method was replaced by the saveObjects (taking an array of objects as the main argument): https://www.algolia.com/doc/api-reference/api-methods/add-objects/

Let me know if that helps,

Cheers