Docs Menu
Docs Home
/ / /
Mongoid
/

Write Data to MongoDB - Sinatra

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 Stack Overflow tag or the MongoDB Reddit community. You can also submit feedback by using the Rate this page tab on the right side of this page.

Back

View Data