Join us Sept 17 at .local NYC! Use code WEB50 to save 50% on tickets. Learn more >
MongoDB Event
Docs 菜单
Docs 主页
/ / /
Mongoid
/

将数据写入MongoDB - Sinatra

1

app.rb文件中,添加名为 add_restaurantpost 路由,如以下代码所示:

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

从应用程序程序根目录运行以下命令,将 Restaurant实例发送到 add_restaurant 端点:

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

在网络浏览器中刷新 http://localhost:4567 /list_restaurants 以查看您提交的新餐厅条目。插入的餐厅将显示在列表底部。

注意

如果您运行问题,请在MongoDB Community论坛中寻求帮助,或使用页面右上角的 Feedback按钮提交反馈。

后退

查看数据