how we can import mongdb collection documents to typesense in node js

170 Views Asked by At

I am having one issue, I searched whole google but couldn't find the answer.

What I want to do is, suppose I have mongo db collection "companies" with 500 records. I have implemented Typesense for search engine, now what I want to do is when I start my application I need to import the existing collection (companies) records to Typesense collection (companies), I don't want to run find query to fetch all records in array and push to typesense collection. I need a proper and better way to implement the replica of mongodb collection to typesense collection.

1

There are 1 best solutions below

0
On

You have to implement it one way or another. But it seems like what you are looking for is a change listener: https://typesense.org/docs/guide/syncing-data-into-typesense.html#using-change-listeners

The change listener will keep your index synced with your DB. However that doesn't include the initial import from your database, which you will have to do somehow (query in mongo + insertion in ts / export to file + import from file)

The doc has an example for MongoDB: https://typesense.org/docs/guide/mongodb-full-text-search.html