Differences between revisions 1 and 2
Revision 1 as of 2008-05-26 15:03:59
Size: 2318
Editor: dslb-084-058-006-155
Comment: Started collecting some info on breaking changes in trunk
Revision 2 as of 2008-05-26 15:13:16
Size: 3161
Editor: dslb-084-058-006-155
Comment: Document bulk update API change
Deletions are marked like this. Additions are marked like this.
Line 58: Line 58:

==== Bulk Updates ====

The JSON structure for bulk updates has been changed slightly for both requests and responses.

For requests, you previously posted a JSON array of document rows. Now, you post a JSON object with a `docs` member containing that array:

{{{
  {
    "docs": [
      {"_id": "foo", "_rev": "123456", "title": "Foo"},
      {"_id": "bar", "_rev": "234567", "title": "Bar"}
    ]
  }
}}}

Responses used to have a JSON object with a `results` member. Now, the response JSON structure looks as follows:

{{{
  {
    "ok": true,
    "new_revs": [
      {"_id": "foo", "rev": "345678"},
      {"_id": "bar", "rev": "456789"}
    ]
  }
}}}

''Note that bulk updates are now transactional: either all updates succeed or all fail. That's why the `ok` member moved to the top-level of the response.''

This page documents backwards-incompatible changes made during the evolution of CouchDB. While not all such changes will necessarily affect all users, most of them probably will. This page should show you what changed and how you'll need to adapt your code.

Changes Between 0.7.x and 0.8.0

Database File Format

The database file format has changed. CouchDB itself does yet not provide any tools for migrating your data. In the meantime, you can use third-party scripts to deal with the migration, such as the dump/load tools that come with the development version (trunk) of couchdb-python.

View Definition Changes

Views now support optional reduce. For this to work, the structure of view definitions in design documents had to change. An example is probably the best way to illustrate this:

  {
    "_id":"_design/foo",
    "language":"javascript",
    "views": {
      "bar": {
        "map":"function... ",
        "reduce":"function..."
      }
    }
  }

Notable changes are the usage of a JSON object to define both the map and the reduce function instead of just a string for the map function. The reduce member may be omitted.

The language member is no longer a MIME type, instead, only the language name is specified. The language name maps exactly to the name chosen for a view server registration in couch.ini.

The map(key, value) function that map functions would use to produce output has been renamed to emit(key, value) to avoid confusion.

  function(doc) {
    emit(doc.foo, doc.bar);
  }

Temporary views now need to get POSTed a JSON document with map and reduce members instead of just POSTing the raw source of the map function:

  {
    "map":"function...",
    "reduce":"function..."
  }

Note that the language of the temporary view is no longer determined by the Content-Type header of the HTTP request. Since the definition is a JSON object, the Content-Type is always application/json. The view language is now specified via an optional language member in the JSON request body. If omitted, the language defaults to "javascript".

  {
    "language":"javascript"
    "map":"function...",
    "reduce":"function..."
  }

HTTP API Changes

Bulk Updates

The JSON structure for bulk updates has been changed slightly for both requests and responses.

For requests, you previously posted a JSON array of document rows. Now, you post a JSON object with a docs member containing that array:

  {
    "docs": [
      {"_id": "foo", "_rev": "123456", "title": "Foo"},
      {"_id": "bar", "_rev": "234567", "title": "Bar"}
    ]
  }

Responses used to have a JSON object with a results member. Now, the response JSON structure looks as follows:

  {
    "ok": true,
    "new_revs": [
      {"_id": "foo", "rev": "345678"},
      {"_id": "bar", "rev": "456789"}
    ]
  }

Note that bulk updates are now transactional: either all updates succeed or all fail. That's why the ok member moved to the top-level of the response.