Nano doesn't provide documentation for temporary views, is there any undocumented method? Failing that, how would you advise somebody execute a temporary view using a nano-like syntax. Currently I am attempting to create the view as _view/guid, query it, return the results, and then delete it from the collection:
function generateToken() {
return Math.floor((1 + Math.random()) * 0x10000).toString(16).substring(1);
}
var db = nano.use('db'),
fn = 'function(doc){ emit(doc); }',
token = generateToken(),
id = '_design/' + token;
db.insert({ views: { view: { map: fn } } }, id, function(){
db.view(token, 'view', function (err, results) {
db.get(id, function (err, view) {
console.log(results);
db.destroy(id, view._rev);
});
});
});
I assume this is inoptimal with the temporary view functionality built into couch core.
I'm aware of the temporary-view caveats, however I do believe I have a genuine usage case.
The temporary view API is described in the official CouchDB documentation: http://docs.couchdb.org/en/latest/api/database/temp-views.html#post--db-_temp_view