How to implement search on nodeJS website using mongoDB database?

Hi. I have a nodeJS web application. There are different “webpages” such as domain.com/about, domain.com/about, domain.com/events, how would I save all the text from all the web pages to a database and search it up when a user inputs a keyword? Basically a search function like https://www.hackingwithswift.com/search/swiftui ?

Hi @sound_cloud,

Welcome to MongoDB community!

MongoDB allows verious ways to search documents and we recommend segregating entities that would need to be fetched together in embedded documents.

For searches you can index “tags” arrays and search in any of the keywords
https://docs.mongodb.com/manual/tutorial/query-arrays/

The server have different indexes like geo and text search.
https://docs.mongodb.com/manual/indexes/#index-types

However, the best full text search experience is provided via our Atlas Search product when you host your database in Atlas.
https://docs.atlas.mongodb.com/atlas-search

Thanks
Pavel

1 Like