Docs Menu

Write Data to MongoDB

1

In the app.rb file, add a post route called add_restaurant, as shown in the following code:

post '/add_restaurant' do
Restaurant.create!(params[:restaurant])
end
2

Send a Restaurant instance to the add_restaurant endpoint by running the following command from the application root directory:

curl -d \
'restaurant[name]=Good+Earth+Cafe&restaurant[cuisine]=Cafe&restaurant[borough]=Queens' \
http://localhost:4567/add_restaurant
3

Refresh http://localhost:4567/list_restaurants in your web browser to view the new restaurant entry that you submitted. The inserted restaurant appears at the bottom of the list.

Note

If you run into issues, ask for help in the MongoDB Community Forums or submit feedback by using the Feedback button in the upper right corner of the page.