Skip to content

dishantkapoor/algolia-scout

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Algolia Scout

Push your data directly on Algolia with AlgoliaScout Package. You can directly connect your model with it and it automatically push your data on algolia.

Installations

Install algolia-scout with npm

  npm install algolia-scout

Logo

Methods

  • algolia.create()
  • algolia.update()
  • algolia.delete()

Explaination

algolia.create()

const AlgoliaScout = require('algolia-scout');

const algolia = new AlgoliaScout();

algolia.index('your_index_name');
algolia.app_id('YOUR_APP_ID');
algolia.app_secret('YOUR_APP_SECRET');

algolia.create(OBJECT, Idetifier_Key, Identifier_Value)
  • OBJECT=the object needs to puch on algolia
  • Idetifier_Key=Key is parameter to check duplicacy
  • Identification_value= Value is need to validate duplicacy

example:

OBJECT

{
    _id:'ajsdjkashdjkahsdkjahsd',
    name:'Dishant Kapoor',
    email:'dishantkpr@gmail.com'
}

Idetifier_Key

'_id'

Identification_value

'ajsdjkashdjkahsdkjahsd'

Documentation

//Create initialization inside Mongoose Model

const AlgoliaScout = require('algolia-scout');

const algolia = new AlgoliaScout();

algolia.index('your_index_name');
algolia.app_id('YOUR_APP_ID');
algolia.app_secret('YOUR_APP_SECRET');


// This Middleware called when we use.save() 
// It will create and Update when already Created

Schema.post('save', async function (doc) {
    // in algolia.create(UPDATED_OBJECT, Idetifier_Key, Identifier_Value);
    algolia.create(doc, '_id', doc._id.toString());
})


Schema.post('findOneAndUpdate', async function (doc) {
    // in algolia.create(Mongoose_doc_ID, Updated Object);
    // use findOneAndUpdate method to auto update in algolia use ,{ new: true } as second argument to get updated value
    algolia.update(doc._id.toString(),doc);
})


Schema.pre('findOneAndDelete', async function (next) {
     // in algolia.delete(Identification_Key, Identification_value);
    const docToDelete = await this.model.findOne(this.getQuery());
    algolia.delete('_id', docToDelete._id.toString())
    next();
});

Badges

MIT License GPLv3 License AGPL License

Authors

About

Algolia Scout for Mongoose

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published