You can watch the screencast here: How to count total attachments in a CouchDB database
And here's the source code for easy copy/paste:
1) I have a 3rd-party-webhook API calling into my update handler and there's nothing I can do to make it pass the document ID in the URL.
2) That means the CouchDB server cannot provide the update function with the most recent version of that document.
3) But the request does provide a payload from which I can pull out the document ID ... but by this time I'm inside the update handler function.
4) So my question is: If CouchDB did not provide a doc, is there still a way for me to:
a) either, fetch the latest version of the doc myself?
b) or, override the existing document with another document formed with my request payload ... without running into a revision conflict?
I know that I can probably route the request through a proxy that parses the payload, sets the document ID onto the request URL and sends it own its way ... but I'd rather leave that as a last resort.
Thoughts?
cd ~/dev/superProject
ln -s ./DerivedData/superProject/Build/Products/Debug-ios-universal/CouchCocoa.framework ./TouchDB-iOS/Demo-iOS/Frameworks/CouchCocoa.framework
<!DOCTYPE html>
<html>
<head>
<title>Address Book</title>
<link rel="stylesheet" href="style/main.css" type="text/css">
</head>
<body>
<h1>Address Book</h1>
<div id="add"><button type="button" id="add">Add</button></div>
<div id="addressbook"></div>
</body>
<script src="vendor/couchapp/loader.js"></script>
<script type="text/javascript" charset="utf-8">
$.couch.app(function(app) {
$("#addressbook").evently("addressbook", app);
});
</script>
</html>
function couchapp_load(scripts) {
for (var i=0; i < scripts.length; i++) {
document.write('<script src="'+scripts[i]+'"><\/script>')
};
};
couchapp_load([
"/_utils/script/sha1.js",
"/_utils/script/json2.js",
"/_utils/script/jquery.js",
"/_utils/script/jquery.couch.js",
"vendor/couchapp/jquery.couch.app.js",
"vendor/couchapp/jquery.couch.app.util.js",
"vendor/couchapp/jquery.mustache.js",
"vendor/couchapp/jquery.evently.js"
]);
$.couch.app(function(app) {
$("#addressbook").evently("addressbook", app);
});
is used to wire-up the addressbook div element with an evently widget (also named addressbook but the names don't really have to match, its not a requirement) which we will be writing later in this tutorial.couchapp generate app addressbook cd addressbook
mkdir -p evently/addressbook/
function () {
$.log('Inside evently/addressbook/_init/query.js');
return {
"view" : "phonenumbers",
};
}function(data) {
$.log('Inside evently/addressbook/_init/data.js');
$.log(data.rows);
return {
"addressbook" : data.rows
};
}{{#addressbook}}
<div class="address">
<span class="name">{{key}}</span>
<span class="phonenumber">{{value}}</span>
<a href="#edit" class="edit">edit</a>
<a href="#delete" class="delete">delete</a>
</div>
{{/addressbook}}
couchapp push
Entering view callback in evently/addressbook/_init.js
jquery...util.js (line 3)
Object { total_rows=2, offset=0, rows=[2]}
jquery...util.js (line 3)
Exiting view callback in evently/addressbook/_init.js
cd vendor/couchapp/_attachments/ wget http://fermyon.iriscouch.com/_utils/script/jquery.couch.js wget http://fermyon.iriscouch.com/_utils/script/sha1.js wget http://fermyon.iriscouch.com/_utils/script/json2.js wget http://fermyon.iriscouch.com/_utils/script/jquery.js
vi vendor/couchapp/_attachments/loader.js
... couchapp_load([ "vendor/couchapp/sha1.js", "vendor/couchapp/json2.js", "vendor/couchapp/jquery.js", "vendor/couchapp/jquery.couch.js", "vendor/couchapp/jquery.couch.app.js", "vendor/couchapp/jquery.couch.app.util.js", "vendor/couchapp/jquery.mustache.js", "vendor/couchapp/jquery.evently.js" ]);
put code here...
| CouchDB | CouchDB-Lucene | CouchIO / CouchOne / CouchBase | Solr | Elastic Search | MongoDB | BigCouch | |
|---|---|---|---|---|---|---|---|
| Full-Text Search | No | Yes | ? | Yes | Yes | May Be with Photovoltaic | ? |
| Distribute-able | Yes | ? | ? | Yes | Yes | ? | ? |
| Distribute-ed | ? | ? | ? | No | Yes | ? | ? |
| Schema-less | Yes | ? | ? | ? | Yes | ? | ? |
| Tools for Importing Data | ? | ? | ? | Yes | ? | ? | ? |
| Comments | ? | Does it go Toe to Toe against all the features of Lucene exposed by Solr? | best for HTML5 dev? | it is distributable but not distributed. SolrCloud has very few features | Compass got punted to invent Elastic Search. | ? | ? |