Skip to content

LocalDocument

Dominic Barnes edited this page May 21, 2014 · 1 revision

LocalDocument(db, [id], [rev])

Represents a CouchDB local document. (ie: it is not replicated) Inherits directly from Document so any methods specified here will override the default behavior of Document.

Note: the _local/ prefix is not required most of the time, as it has been handled by the LocalDocument#id() method in place of the Document#id() method. However, if you are specifying the body directly, you will need to remember to do this yourself.

var couchdb = require("couchdb-api");

var db = couchdb().db("mydb");

// creates a local document object with a known id
var ldoc = db.ldoc("myldoc");

// creates a local document object with a predefined body
var ldoc = db.ldoc({
    hello: "world"
});

LocalDocument#id([id])

This helper method gets or sets the _id property on the body of this document.

Note: this method has special behavior for LocalDocument, in that it will prefix _id with _local/ when using as a setter.

// getter
var id = ldoc.id();

// setter (no _local/ prefix required)
ldoc.id("my-other-ldoc");
Clone this wiki locally