Javascript News - A collection of audio articles aimed toward Full Stack Development with JS.

Text Search With MongoDB


Listen Later

When working with large databases it is often accusatory to want to be able to find specific keywords in this database. Over the next few minutes I will be explaining how to create search indexes in MongoDB. Creating a search engine in MongoDB allows for one to be able to text search with Mongoose. This will be done using Nodejs and Expressjs.

First one wants to create a search index with the MongDB Shell. To do this one wants to type in the following command with the MongoDB Shell. Note this command is straight from the MongoDB Docs that can be found in the references section.

db.tasks.createIndex({ task: “text” }); (Mongodb, n.d.)

This command creates an index on the tasks collection and allows for the next link of code which will search the tasks collection for the task item.

db.tasks.find({ $text: { $search: “learn Angular” }})

This line of code searches the tasks collection for the task item for the term “learn Angular”. From there the data can be displayed and allows for one to display the data on the front-end.

Feel free to subscribe! Happy adventures in code!

Reference

MongoDB. (n.d.). Text Search. Retrieved from https://docs.mongodb.com/manual/text-search/.

---
This episode is sponsored by
· Anchor: The easiest way to make a podcast. https://anchor.fm/app
---
Send in a voice message: https://anchor.fm/javascript-news/message
Support this podcast: https://anchor.fm/javascript-news/support
...more
View all episodesView all episodes
Download on the App Store

Javascript News - A collection of audio articles aimed toward Full Stack Development with JS.By Javascript News