Hello! ๐ This application allows you to search lightning fast through over 25,000 restaurants in the New York city area based on a variety of search parameters and data types:
- restaurant name
- geolocation coordinates
- cuisine type
- average star rating
- borough
Note: This dataset is mocked. Please do not use to make actual dining decisions.
What's Cooking implements many Atlas Search features from autocomplete to custom function scoring. Using the $search operator in a MongoDB aggregation pipeline, we can build fine-grained searches across text, numerics, and geospatial data. By building out What's Cooking, you'll learn all sorts of ways MongoDB allows you to build complex, fine-grained full-text searches on your Atlas data.
No additional servers or software needed. No need to keep data in sync. Everything is done in MongoDB Atlas.
- fuzzy matching
- highlighting
- autocomplete
- range queries
- geoqueries
- facets
- relevance-based scoring
- custom function scoring
- synonyms
Check out the video of the MongoDB.Live keynote to see a demonstration of all the features or visit the link below to play around with the finished application, hosted entirely in MongoDB Atlas:
This application is hosted entirely by MongoDB Atlas was created using:
- React
- Tailwind CSS
- MongoDB Realm for backend HTTPs endpoints and webhooks
- A modified sample dataset based on MongoDB's Atlas sample_restaurants dataset
Currently this app is not suitable for mobile, but feel free to send a PR. ๐
- A MongoDB Atlas account. Get one for free here.
- A recent version of Node.js and npm.
- Restaurant sample dataset.
- Synonyms dataset.
- (Recommended) MongoDB Compass - GUI
You can read and download the dataset using the MongoDB Shell, any MongoDB driver, or my favorite MongoDB Compass using the following URI:
mongodb+srv://mongodb:[email protected]/whatscooking
It is also included in this repo's Supplemental Files branch as
whatscooking.json
- Load data to Atlas cluster:
- database:
whatscooking - collection:
restaurants,menu_synonyms
- database:
- Create Search indexes. (Index definitions includes in
indexesdirectory.)
- Create Application At your Atlas UI, click
- Create HTTPS Endpoints Go to
- Function Setting Go to
- Deploy app At the top of UI, click
Create a New AppName your application whatever you wish.
After ensuring it is linked to the correct cluster, click the CREATE APP SERVICE button.
HTTPS Endpoints at navigation bar at left and click Add An EndpointCreate following 3 HTTP endpoints
| Route | Source code of function | HTTP methods | Respond With Result | Return Type |
|---|---|---|---|---|
| /restaurants/getRestaurantsAutocomplete | _backend_functions/getRestaurantsAutocomplete.js | GET | Enable | JSON |
| /getRestaurants | _backend_functions/getRestaurants.js | POST | Enable | JSON |
| /restaurants/getFacets | _backend_functions /getFacets.js | POST | Enable | JSON |
| /synonyms/getFoodSynonyms | _backend_functions/getFoodSynonyms.js | POST | Enable | JSON |
Please keep default value for other options and click Save Draft
Function at navigation bar at leftAt each function which you created, go to
Settings tab, choose System at Authentigation and click Save Draft
REVIEW DRAFT & DEPLOY
$curl https://ap-southeast-1.aws.data.mongodb-api.com/app/whatscooking-XXXXX/endpoint/restaurants/getRestaurantsAutocomplete?restname="burger"response
[{"_id":"6095a34a7c34416a90d3212d","name":"Burger King","restaurant_id":"40370238"},{"_id":"6095a34a7c34416a90d3212e","name":"Burger King","restaurant_id":"40370167"},{"_id":"6095a34a7c34416a90d32135","name":"Burger King","restaurant_id":"40370239"},{"_id":"6095a34a7c34416a90d3214b","name":"Burger King","restaurant_id":"40370916"},{"_id":"6095a34a7c34416a90d32164","name":"Burger King","restaurant_id":"40370917"},{"_id":"6095a34a7c34416a90d32166","name":"Burger King","restaurant_id":"40372422"},{"_id":"6095a34a7c34416a90d3216b","name":"Burger King","restaurant_id":"40372618"},{"_id":"6095a34a7c34416a90d321b4","name":"Cozy Soup \u0026 Burger","restaurant_id":"40375839"},{"_id":"6095a34a7c34416a90d3228a","name":"Burger Barn Restaurant","restaurant_id":"40384486"}]
command
curl \
-H "Content-Type: application/json" \
-d '{"searchTerm": "burger ", "food": "", "operator": "text", "dist": 1, "stars": 1, "cuisine": []}' \
https://ap-southeast-1.aws.data.mongodb-api.com/app/whatscooking-qztoq/endpoint/getRestaurants
response
{"aggString":"[{\"$search\":{\"text\":{\"query\":\"burger \",\"path\":\"name\",\"fuzzy\":{\"maxEdits\":2}}}},{\"$limit\":21},{\"$project\":{\"name\":1,\"cuisine\":1,\"borough\":1,\"location\":1,\"menu\":1,\"restaurant_id\":1,\"address.street\":1,\"stars\":1,\"review_count\":1,\"PriceRange\":1,\"sponsored\":1,\"score\":{\"$meta\":\"searchScore\"},\"highlights\":{\"$meta\":\"searchHighlights\"}}}]","restaurants":[{"_id":"6095a4864ba3a04a69a79eba","address":{"street":"Pearl Street"},"borough":"Manhattan","cuisine":"Hamburgers","name":"Burger Burger","restaurant_id":"41316784","location":{"type":"Point","coordinates":[-74.0105051,40.7040805]},"stars":3.5,"review_count":159,"menu":["Bacon burger","Santa Fe burger","Ahi Tuna burger","Cheeseburger","Loaded Fries","Mushroom swiss burger","Hickory burger","Classic burger","Fajita burger","Oldtimer with cheese","French Fries","Vegetarian burger"],"PriceRange":2,"score":3.3074374198913574},{"_id":"6095a34a7c34416a90d3212d","address":{"street":"Northern Boulevard"},"borough":"Queens","cuisine":"Hamburgers","name":"Burger King","restaurant_id":"40370238","location":{"type":"Point","coordinates":[-73.89707140000002,40.7543896]},"stars":3,"review_count":38,"menu":["Cheeseburger","Ahi Tuna burger","Chili Cheeseburger","Buffalo Fries","Vegetarian burger","Loaded Fries","French Fries","Classic burger","Triple layer burger","Oldtimer with cheese","Hickory burger","Oldtimer"],"PriceRange":2,"score":2.49027419090271}, ...}
command
curl \
-H "Content-Type: application/json" \
-d '{"searchTerm": "burger", "food": "", "operator": "text", "dist": 1, "stars": 1, "cuisine": []}' \
https://ap-southeast-1.aws.data.mongodb-api.com/app/whatscooking-qztoq/endpoint/restaurants/getFacets
response
{"results":[{"count":{"lowerBound":183},"facet":{"cuisineFacet":{"buckets":[{"_id":"Hamburgers","count":105},{"_id":"American","count":69},{"_id":"Other","count":3},{"_id":"Jewish/Kosher","count":2},{"_id":"Pizza/Italian","count":2},{"_id":"Latin (Cuban, Dominican, Puerto Rican, South \u0026 Central American)","count":1},{"_id":"Mexican","count":1}]},"boroughFacet":{"buckets":[{"_id":"Manhattan","count":69},{"_id":"Brooklyn","count":47},{"_id":"Queens","count":36},{"_id":"Bronx","count":23},{"_id":"Staten Island","count":8}]}}}],"searchMetaStageString":"{\"$searchMeta\":{\"index\":\"facetIndex\",\"facet\":{\"operator\":{\"text\":{\"query\":\"burger\",\"path\":[\"name\",\"cuisine\"]}},\"facets\":{\"cuisineFacet\":{\"type\":\"string\",\"path\":\"cuisine\"},\"boroughFacet\":{\"type\":\"string\",\"path\":\"borough\"}}}}}","searchMetaStage":{"$searchMeta":{"index":"facetIndex","facet":{"operator":{"text":{"query":"burger","path":["name","cuisine"]}},"facets":{"cuisineFacet":{"type":"string","path":"cuisine"},"boroughFacet":{"type":"string","path":"borough"}}}}},"ok":true}
๐ง
- Clone the repo.
- Navigate inside
WhatsCookingdirectory. - Run
npm install. - Change HTTPS endpoint urls at
src/hooks/useHomeFetch.jsto your own ones. - Change HTTPS endpoint urls at
src/compenents/SearchBar.jsto your own one. - Change MongoDB Connectionstring at
src/pages/IndexPage.jsto your own one. - Run
npm start.
- Make sure that you're using NodeJS v16 to successfully build the artifacts
- Set AWS temporary credentials in your environment variable and ensure that you're pointing to the correct AWS account
- Run
./deploy_to_s3.sh
What's Cooking uses HTTP services in Realm to create 5 APIs to allow you to query for your restaurant data over HTTP:
GetRestaurantsEndPointcalled from theuseHomeFetch.jshook.GetFacetsEndpointcalled from theuseHomeFetch.jshook.Suggestions_AC_Endpointcalled from theSearchBar.jscomponent.getSynonymscalled in theSynonymsPage.js.
Find the Realm application and code for these webhooks in the
WhatsCookingRealm folder.






