gwendall:mongo-algolia-sync

v0.1.1Published 10 years ago

This package has not had recent updates. Please investigate it's current state before committing to using it in your project.

Meteor Mongo Algolia Sync

Automatically sync a Mongo collection to an Algolia index.

Installation

meteor add gwendall:mongo-algolia-sync

Methods

MongoCollection.syncAlgolia(AlgoliaIndex, options)

Keeps track of all documents inserted / updated / removed within a Mongo collection, and performs the equivalent operations to an Algolia index.

1// Server-only
2AlgoliaClient = AlgoliaSearch(ALGOLIA_APP_ID, ALGOLIA_SECRET_KEY);
3AlgoliaIndex = AlgoliaClient.initIndex('posts');
4MongoCollection = new Mongo.Collection('posts');
5MongoCollection.syncAlgolia(AlgoliaIndex, {
6  debug: true,
7  transform: function(doc) {
8    delete doc.secret;
9    return doc;
10  }
11});

Options:

  • debug (boolean): Console logs operations or not (false by default).
  • transform (function): Allows to transform the documents that will be saved to Algolia (return false to prevent syncing a given document).

MongoCollection.initAlgolia(AlgoliaIndex, options)

Performs the initial sync of all the documents in the given Mongo collection to the given Algolia index.

1// Server-only
2MongoCollection.initAlgolia(AlgoliaIndex, {
3  clearIndex: true
4});

Options (same as above + the following):

  • clearIndex: Empty the Algolia index on start (false by default).
  • mongoSelector: Mongo selector for the cursor that will be synced to Algolia ({} by default).
  • mongoOptions: Mongo options for the cursor that will be synced to Algolia ({} by default).

Notes

  • The Algolia indexes can be created with the acemtp:algolia package.
  • The Algolia objectID used will be the _id of the Mongo documents.