Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Databases

dylan kane
dylan kane
2,772 Points

Whats the best way to make a working search bar with my mongo db?

I am creating a web app where I have a database of games, and I need to have a search bar that a user can type a game name into, and it will get pulled from the database with all the information. I'm not sure what is a good way to go about doing this, and btw for some background info, i am using meteor so perhaps that will help narrow down the answer. I am willing to learn how to code this myself but I just want to make sure there isn't a better way to do this. I'm pretty new to the database field, so this all seems very confusing, any help would be great!

Jason Anders
Jason Anders
Treehouse Moderator 145,860 Points

Sorry Dylan,

I haven't worked with MongoDB before, so I'm not able to help here.

1 Answer

Ken Alger
STAFF
Ken Alger
Treehouse Teacher

Dylan;

It really should not matter what database you are using if you separate your technology appropriately. Typically you would generate a RESTful API that "talks" to whatever database you are using and returns the results. Then your front-end would be making the necessary requests (AJAX perhaps?) to the API.

By doing things in this fashion your application becomes more manageable and maintainable in the long run. As an example, if you decide to use something other than Meteor for the "front-end" your API wouldn't have to be changed. This is a common model for applications.

In terms of how you get your search box to dynamically fill itself out depending on what is being entered, there are jQuery and/or Javascript implementations for that. Like I said, those should be designed in a database independent fashion so that it doesn't matter if you are using MongoDB, documentDB, MySQL, or Redis, for example.

Hope that helps and happy coding,
Ken

dylan kane
dylan kane
2,772 Points

So if I were to hook restful api up to my project, would the user be able to interact with that and then it would pull data from the database?

Ken Alger
Ken Alger
Treehouse Teacher

Dylan;

Just setting up a RESTful API will not get the functionality you want necessarily, but it would be one option for getting you headed in that direction.

Ken