Docs Menu
Docs Home
/ /

MongoDB 에 데이터 쓰기 - Sinatra

1

다음 코드에 표시된 대로 app.rb 파일 에서 add_restaurant(이)라는 post 경로를 추가합니다.

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 Stack Overflow 태그를 지정하다 또는 MongoDB Reddit Community에서 도움을 요청하세요. 이 페이지의 오른쪽에 있는 Rate this page 탭 사용하여 피드백 제출 수도 있습니다.

돌아가기

데이터 보기