13. JSON Structure Reference
The following appendix provides a quick reference to all the JSON structuresthat you can supply to CouchDB, or get in return to requests.
13.1. All Database Documents
Field |
Description |
total_rows |
Number of documents in the database/view |
offset |
Offset where the document list started |
update_seq (optional) |
Current update sequence for the database |
rows [array] |
Array of document object |
13.2. Bulk Document Response
Field |
Description |
docs [array] |
Bulk Docs Returned Documents |
id |
Document ID |
error |
Error type |
reason |
Error string with extended reason |
13.3. Bulk Documents
Field |
Description |
docs [array] |
Bulk Documents Document |
_id (optional) |
Document ID |
_rev (optional) |
Revision ID (when updating an existingdocument) |
_deleted (optional) |
Whether the document should be deleted |
Field |
Description |
last_seq |
Last update sequence |
pending |
Count of remaining items in the feed |
results [array] |
Changes made to a database |
seq |
Update sequence |
id |
Document ID |
changes [array] |
List of changes, field-by-field, for thisdocument |
13.5. CouchDB Document
Field |
Description |
_id (optional) |
Document ID |
_rev (optional) |
Revision ID (when updating an existingdocument) |
13.6. CouchDB Error Status
Field |
Description |
id |
Document ID |
error |
Error type |
reason |
Error string with extended reason |
Field |
Description |
db_name |
The name of the database. |
committed_update_seq |
The number of committed updates. |
doc_count |
The number of documents in the database. |
doc_del_count |
The number of deleted documents. |
compact_running |
Set to true if the database compactionroutine is operating on this database. |
disk_format_version |
The version of the physical format used forthe data when it is stored on hard disk. |
disk_size |
Size in bytes of the data as stored on disk.View indexes are not included in thecalculation. |
instance_start_time |
Timestamp indicating when the database wasopened, expressed in microseconds since theepoch. |
purge_seq |
The number of purge operations on thedatabase. |
update_seq |
Current update sequence for the database. |
13.8. Design Document
Field |
Description |
_id |
Design Document ID |
_rev |
Design Document Revision |
views |
View |
viewname |
View Definition |
map |
Map Function for View |
reduce (optional) |
Reduce Function for View |
Field |
Description |
name |
Name/ID of Design Document |
view_index |
View Index |
compact_running |
Indicates whether a compaction routine iscurrently running on the view |
disk_size |
Size in bytes of the view as stored on disk |
language |
Language for the defined views |
purge_seq |
The purge sequence that has been processed |
signature |
MD5 signature of the views for the designdocument |
update_seq |
The update sequence of the correspondingdatabase that has been indexed |
updater_running |
Indicates if the view is currently beingupdated |
waiting_clients |
Number of clients waiting on views from thisdesign document |
waiting_commit |
Indicates if there are outstanding commitsto the underlying database that need toprocessed |
13.10. Document with Attachments
Field |
Description |
_id (optional) |
Document ID |
_rev (optional) |
Revision ID (when updating an existingdocument) |
_attachments (optional) |
Document Attachment |
filename |
Attachment information |
content_type |
MIME Content type string |
data |
File attachment content, Base64 encoded |
13.11. List of Active Tasks
Field |
Description |
tasks [array] |
Active Tasks |
pid |
Process ID |
status |
Task status message |
task |
Task name |
type |
Operation Type |
13.12. Replication Settings
Field |
Description |
source |
Source database name or URL. |
target |
Target database name or URL. |
cancel (optional) |
Cancels the replication. |
checkpoint_interval (optional) |
Specifies the checkpoint interval in ms. |
continuous (optional) |
Configure the replication to be continuous. |
create_target (optional) |
Creates the target database. |
doc_ids (optional) |
Array of document IDs to be synchronized. |
filter (optional) |
name of the filter function in the form ofddoc/myfilter . |
proxy (optional) |
Address of a proxy server through whichreplication should occur. |
query_params (optional) |
Query parameter that are passed to thefilter function; the value should be adocument containing parameters as members. |
selector (optional) |
Select the documents included in thereplication. This option providesperformance benefits compared with usingthe filter option. |
since_seq (optional) |
Sequence from which the replication shouldstart. |
use_checkpoints (optional) |
Whether to use replication checkpointsor not. |
13.13. Replication Status
Field |
Description |
ok |
Replication status |
session_id |
Unique session ID |
source_last_seq |
Last sequence number read from the sourcedatabase |
history [array] |
Replication History |
session_id |
Session ID for this replication operation |
recorded_seq |
Last recorded sequence number |
docs_read |
Number of documents read |
docs_written |
Number of documents written to target |
doc_write_failures |
Number of document write failures |
start_time |
Date/Time replication operation started |
start_last_seq |
First sequence number in changes stream |
end_time |
Date/Time replication operation completed |
end_last_seq |
Last sequence number in changes stream |
missing_checked |
Number of missing documents checked |
missing_found |
Number of missing documents found |
13.14. Request object
Field |
Description |
body |
Request body data as string.If the request method is GET this fieldcontains the value "undefined" . If themethod is DELETE or HEAD the value is"" (empty string). |
cookie |
Cookies object. |
form |
Form data object.Contains the decoded body as key-valuepairs if the Content-Type header wasapplication/x-www-form-urlencoded . |
headers |
Request headers object. |
id |
Requested document id string if it wasspecified or null otherwise. |
info |
Database information |
method |
Request method as string or array.String value is a method as one of: HEAD,GET, POST, PUT, DELETE, OPTIONS,and TRACE. Otherwise it will berepresented as an array of char codes. |
path |
List of requested path sections. |
peer |
Request source IP address. |
query |
URL query parameters object.Note that multiple keys are not supportedand the last key value suppresses others. |
requested_path |
List of actual requested path section. |
raw_path |
Raw requested path string. |
secObj |
Security Object. |
userCtx |
User Context Object. |
uuid |
Generated UUID by a specified algorithm inthe config file. |
- {
- "body": "undefined",
- "cookie": {
- "AuthSession": "cm9vdDo1MDZBRjQzRjrfcuikzPRfAn-EA37FmjyfM8G8Lw",
- "m": "3234"
- },
- "form": {},
- "headers": {
- "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
- "Accept-Charset": "ISO-8859-1,utf-8;q=0.7,*;q=0.3",
- "Accept-Encoding": "gzip,deflate,sdch",
- "Accept-Language": "en-US,en;q=0.8",
- "Connection": "keep-alive",
- "Cookie": "m=3234:t|3247:t|6493:t|6967:t|34e2:|18c3:t|2c69:t|5acb:t|ca3:t|c01:t|5e55:t|77cb:t|2a03:t|1d98:t|47ba:t|64b8:t|4a01:t; AuthSession=cm9vdDo1MDZBRjQzRjrfcuikzPRfAn-EA37FmjyfM8G8Lw",
- "Host": "127.0.0.1:5984",
- "User-Agent": "Mozilla/5.0 (Windows NT 5.2) AppleWebKit/535.7 (KHTML, like Gecko) Chrome/16.0.912.75 Safari/535.7"
- },
- "id": "foo",
- "info": {
- "committed_update_seq": 2701412,
- "compact_running": false,
- "data_size": 7580843252,
- "db_name": "mailbox",
- "disk_format_version": 6,
- "disk_size": 14325313673,
- "doc_count": 2262757,
- "doc_del_count": 560,
- "instance_start_time": "1347601025628957",
- "purge_seq": 0,
- "update_seq": 2701412
- },
- "method": "GET",
- "path": [
- "mailbox",
- "_design",
- "request",
- "_show",
- "dump",
- "foo"
- ],
- "peer": "127.0.0.1",
- "query": {},
- "raw_path": "/mailbox/_design/request/_show/dump/foo",
- "requested_path": [
- "mailbox",
- "_design",
- "request",
- "_show",
- "dump",
- "foo"
- ],
- "secObj": {
- "admins": {
- "names": [
- "Bob"
- ],
- "roles": []
- },
- "members": {
- "names": [
- "Mike",
- "Alice"
- ],
- "roles": []
- }
- },
- "userCtx": {
- "db": "mailbox",
- "name": "Mike",
- "roles": [
- "user"
- ]
- },
- "uuid": "3184f9d1ea934e1f81a24c71bde5c168"
- }
13.15. Request2 object
Field |
Description |
body |
Request body data as string.If the request method is GET this fieldcontains the value "undefined" . If themethod is DELETE or HEAD the value is"" (empty string). |
cookie |
Cookies object. |
headers |
Request headers object. |
method |
Request method as string or array.String value is a method as one of: HEAD,GET, POST, PUT, DELETE, OPTIONS,and TRACE. Otherwise it will berepresented as an array of char codes. |
path |
List of requested path sections. |
peer |
Request source IP address. |
query |
URL query parameters object.Note that multiple keys are not supportedand the last key value suppresses others. |
requested_path |
List of actual requested path section. |
raw_path |
Raw requested path string. |
secObj |
Security Object. |
userCtx |
User Context Object. |
13.16. Response object
Field |
Description |
code |
HTTP status code number. |
json |
JSON encodable object.Implicitly sets Content-Type header asapplication/json . |
body |
Raw response text string.Implicitly sets Content-Type header astext/html; charset=utf-8 . |
base64 |
Base64 encoded string.Implicitly sets Content-Type header asapplication/binary . |
headers |
Response headers object.Content-Type header from this objectoverrides any implicitly assigned one. |
stop |
boolean signal to stop iteration overview result rows (for list functions only) |
Warning
The body
, base64
and json
object keys are overlapping each otherwhere the last one wins. Since most realizations of key-value objects donot preserve the key order or if they are mixed, confusing situations canoccur. Try to use only one of them.
Note
Any custom property makes CouchDB raise an internal exception. Furthermore,the Response object could be a simple string value which would beimplicitly wrapped into a {"body": …}
object.
13.17. Returned CouchDB Document with Detailed Revision Info
Field |
Description |
_id (optional) |
Document ID |
_rev (optional) |
Revision ID (when updating an existingdocument) |
_revs_info [array] |
CouchDB document extended revision info |
rev |
Full revision string |
status |
Status of the revision |
13.18. Returned CouchDB Document with Revision Info
Field |
Description |
_id (optional) |
Document ID |
_rev (optional) |
Revision ID (when updating an existingdocument) |
_revisions |
CouchDB document revisions |
ids [array] |
Array of valid revision IDs, in reverseorder (latest first) |
start |
Prefix number for the latest revision |
13.19. Returned Document with Attachments
Field |
Description |
_id (optional) |
Document ID |
_rev (optional) |
Revision ID (when updating an existingdocument) |
_attachments (optional) |
Document attachment |
filename |
Attachment |
stub |
Indicates whether the attachment is a stub |
content_type |
MIME Content type string |
length |
Length (bytes) of the attachment data |
revpos |
Revision where this attachment exists |
13.20. Security Object
Field |
Description |
admins |
Roles/Users with admin privileges |
roles [array] |
List of roles with parent privilege |
names [array] |
List of users with parent privilege |
members |
Roles/Users with non-admin privileges |
roles [array] |
List of roles with parent privilege |
names [array] |
List of users with parent privilege |
- {
- "admins": {
- "names": [
- "Bob"
- ],
- "roles": []
- },
- "members": {
- "names": [
- "Mike",
- "Alice"
- ],
- "roles": []
- }
- }
13.21. User Context Object
Field |
Description |
db |
Database name in the context of theprovided operation. |
name |
User name. |
roles |
List of user roles. |
- {
- "db": "mailbox",
- "name": null,
- "roles": [
- "_admin"
- ]
- }
Field |
Description |
total_rows |
Number of documents in the view |
offset |
Offset where the document list started |
- {
- "total_rows": 42,
- "offset": 3
- }
原文: http://docs.couchdb.org/en/stable/json-structure.html