【发布时间】:2015-11-10 18:42:04
【问题描述】:
我正在向我的 Ruby 驱动程序发送以下 curl 请求
curl -i -X POST -H "Content-Type:application/json" -d '{ "firstName" : "Frodo", "lastName" : "Baggins" }' http://localhost:4567/new_document/?
这是 ruby 中 POST 操作的代码。
post '/new_document/?' do
content_type :json
db = settings.mongo_db
result = db.insert_one params
db.find(:_id => result.inserted_id).to_a.first.to_json
end
我在控制台中得到以下响应。
HTTP/1.1 200 OK
Content-Type: application/json
Content-Length: 43
X-Content-Type-Options: nosniff
Server: WEBrick/1.3.1 (Ruby/2.0.0/2013-11-22)
Date: Tue, 10 Nov 2015 18:38:59 GMT
Connection: Keep-Alive
{"_id":{"$oid":"564239c3e89bde194d000007"}}
正如您所见,永远不会创建名字和姓氏字段。我做错了什么?
【问题讨论】:
标签: ruby mongodb curl terminal