JavaScript Programming

I'm not getting any data from my Ajax request

Browsers can only request data served from the same domain as the host. Stick your HTML file in CouchDB as a binary attachment to fix this. More info in the second part of this article.

How do I use $.couch.app() behind a vhost?

Here is a rewrite rule that makes the application's database available through the vhost

And here is how you hint to the $.couch.app() the ddoc URL without it having to inspect it from the document.location.

How do use the same CommonJS libraries on the client and the server?

CouchApp Toolchain

How can I make CouchApp automatically update my design document when I save files?

SInce 0.7, couchapp contains the "autopush" extension. To install it, add these lines to your setting file .couchapprc:

{ 
    "extensions": [ 
        "egg:couchapp#autopush" 
    ] 
} 

Then launch autopush server in the couchapp folder :

couchapp autopush --update-delay 10 . testdb 

This command send changes every 10 seconds to the testdb database. autopush use linux inotify API if pyinotify module is installed. Eventlet is required for this feature.

I edit some files and push them into the database, but when I look into the _design, the file contents haven't changed!!

This happens when your editor keeps the old unchanged file around, e.g. by appending a ~. Then couchapp loads both the new and the old version of the file and (as Murphy dictates) the old version wins.

Solution: see the next point on how to make couchapp ignore those backup files.

How do I specify files to ignore?

A .couchappignore file specifies intentionally untracked files that couchapp should ignore. It's a simple json file containing an array of regexps that will be use to ignore file.

For example:

 [
   ".*\\.swp$",
   ".*~$"
]

will ignore all files ending in .swp and ~ . Be sure to leave out the final , in the list.

You can check if couchapp really ignores the files by specifying the -v option: couchapp -v push ...

Note: windows doesn't like files that only have an extension, so creating the .couchappignore file will be a challenge in windows. Possible solutions to creating this file are :

  1. Using cygwin, type: touch .couchappignore
  2. cd /to/couchappand then notepad .couchappignore

How do I reference the built-in reduce functions?

Since the contents of the reduce.js file associated with each view is properly escaped and then inserted into the design document as a quoted string, all you need to do to use one of the built-in reduce functions is insert one of the following lines into the file (without quotes or whitespace):

_sum
_count
_stats