Commands: Documents: Put

Put is used to insert or update a document in a database.


curl \
	http://{serverUrl}/databases/{databaseName}/docs/{key}  \
	-X PUT \
	-d @jsonData.txt  \
	--header "anyKey:anyValue" \
    --header "If-None-Match:{etag}" 
curl \
	http://{serverUrl}/databases/{databaseName}/docs \
	-X POST \
	-d @jsonData.txt  \
	--header "anyKey:anyValue" \	
    --header "If-None-Match:{etag}"


Method Description
POST document key isn't passed in url and is auto-generated on server side
PUT document key is passed in url
Json document data
Query parameter Required Description
key for PUT unique key under which document will be stored
Header Required Description
If-None-Match No Used to pass document Etag
Any other header No Used to pass document metadata


Status code Description
200 OK - for POST
201 Created - for PUT
409 When concurrency exception occurred
Return Value Description
Key unique key under which document was stored
Etag stored document etag


Put document under key items/1 with CreatedBy and ItemOwner in metadata.

curl \
	-X PUT http://localhost:8080/docs/items/1  \
	-d "{ }"  \
	--header "CreatedBy:Adam Smith" \
	--header "ItemOwner:John Davis"
< HTTP/1.1 201 Created

Put document and auto-generate key on server side.

curl -X POST http://localhost:8080/docs \
	-d "{ FirstName: 'Bob', LastName: 'Smith', Address: '5 Elm St' }"
< HTTP/1.1 200 OK

Attempting to put document with invalid etag ends up with conflict.

curl -X PUT http://localhost:8080/docs/user/100  \
	-d "{ }" 
< HTTP/1.1 201 Created
curl -X PUT http://localhost:8080/docs/user/100 \
	-d "{ }" \
	--header "If-None-Match:01000000-0000-0008-0000-0000000000CC" 
< HTTP/1.1 409 Conflict
	"Error":"PUT attempted on document 'user/100' using a non current etag"