Wednesday 17 May 2017

Access Firebase Child Node in Node.js - Firebase Cloud Functions

Here is how my Firebase Schema is laid out: enter image description here

I am able to index everything except _geoloc: into my Algolia Index with this code:

'use strict';

const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);

// Authenticate to Algolia Database.
// TODO: Make sure you configure the `algolia.app_id` and `algolia.api_key` Google Cloud environment variables.
const algoliasearch = require('algoliasearch');
const client = algoliasearch(functions.config().algolia.app_id, functions.config().algolia.api_key);

// Name fo the algolia index for content.
const ALGOLIA_POSTS_INDEX_NAME = 'businessSearch';


exports.indexentry = functions.database.ref('/businessSearch/{uid}/').onWrite(event => {
    const index = client.initIndex(ALGOLIA_POSTS_INDEX_NAME);
    const firebaseObject = Object.assign({}, event.data.val(), {
      functions.database.ref('/businessSearch/{uid}/_geoloc').onWrite(event =>{

      })
      objectID: event.params.uid,
    });

    index.saveObject(firebaseObject); // .then or .catch as well
    index.addObject
  });

How can I index the _geoloc: child node into my Algolia Index with Node.js?

I heard somewhere that this is not possible, but I just wanted to see if it was.



via ethanfox27

No comments:

Post a Comment