0
我送下面捲曲請求我的Ruby驅動程序MongoDB與Ruby驅動程序如何使用curl創建字段?
curl -i -X POST -H "Content-Type:application/json" -d '{ "firstName" : "Frodo", "lastName" : "Baggins" }' http://localhost:4567/new_document/?
這是在紅寶石的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"}}
正如你所看到的,字段的名字和姓氏都不會被創建。我究竟做錯了什麼?