1

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.

Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
Dom Vinyard
  • 2,038
  • 1
  • 23
  • 36

3 Answers3

1

Open up futon and see what calls it does to the couchDB api ?

Edit: went and did the above

Futon does a post to SVRNAME/DBNAME/_temp_view?limit=11&descending=true request payload {language: "javascript" map: function(doc) { emit(null, doc.id);} and you must be logged in as an admin.

Hope that helps

Adam
  • 55
  • 6
1

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

Aurélien Bénel
  • 3,775
  • 24
  • 45
0

I think you could do this through Nano using nano.request() (or nano.dinosaur()). https://github.com/dscape/nano#nanorequestopts-callback

Jeff Lowery
  • 2,492
  • 2
  • 32
  • 40