Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing part of a document using CouchDB PUT

Tags:

couchdb

Reading the documentation (and playing around with the software), it looks like a PUT command will replace the entire existing document (create a new revision which includes only what was sent in PUT command). Is there a way to update part of a document?

For example, let's say a POST command creates a document with the following JSON object:

{"name" : "Chuck"}

Then a PUT command on the same document id adds:

{"lastname" : "Norris"}

Is there a way to get CouchDB to return the combination of the two revisions, as opposed to just the latest update? Otherwise any change to a document will require retrieving the complete document, and sending the complete (updated) document back.

like image 317
Alon Weinstein Avatar asked Dec 06 '10 06:12

Alon Weinstein


People also ask

How do I edit a document in CouchDB?

You can also update/ change/ edit your document once you created. Click on the edit option (encircled in red). After clicking, you will get a new page where you can edit your entries. After editing click on the save changes tab and your document will be updated.

Is CouchDB document based?

Apache CouchDB is an open-source document-oriented NoSQL database, implemented in Erlang. CouchDB uses multiple formats and protocols to store, transfer, and process its data. It uses JSON to store data, JavaScript as its query language using MapReduce, and HTTP for an API.

Which of the following are inbuilt reduce functions of Apache CouchDB?

CouchDB has three built-in Reduce functions: _count , _sum , and _stats (shown in Table 2-5).

How do I insert a document into CouchDB?

Open the Overview page of the database and select New Document option as shown below. When you select the New Document option, CouchDB creates a new database document, assigning it a new id. You can edit the value of the id and can assign your own value in the form of a string.


1 Answers

Try looking into Document Update Handlers: when an update handler is PUT from your application, the corresponding JavaScript function will be called with the data your application sent and the existing document on the server, which lets it merge the two pieces of data appropriately.

like image 148
Victor Nicollet Avatar answered Oct 01 '22 12:10

Victor Nicollet