Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    hellboy81
    @hellboy81
    with some JSON data
    where can I call this callback?
    // Should I call result callback from `cb`
    var ws = db.attachment.insert(documentName, attName, null, mimetype, {rev : response.rev}, function(...) {})
    
    // Or should I call in on ('end') event
    ws.on('end',  ...)
    
    // Should I catch write stream errors?
    ws.on('error', function (err) {...})
    
    // Should I catch input stream errors?
    file.on('error',  function(err) {...})
    
    file.pipe(ws)
    hellboy81
    @hellboy81
    Can you verify my code?
    Dominique Sandoz
    @streunerlein
    hi @hellboy81, this is how I do it (read file from disk, pipe to db attachment ):
    // add attachment
            var dbWriteStream = db.attachment.insert(doc._id, filename, null, type, {rev: doc._rev}, uploaded);
            var fileReadStream = fs.createReadStream(file.path);
    
            fileReadStream.on('error', error);
    
            dbWriteStream.on('error', error);
    
            fileReadStream.pipe(dbWriteStream);
    uploaded is the callback that gets called when piping is complete
    then, uploaded():
     function uploaded(err, body) {
              if (err) {
                console.log("[Attachment] Error in upload.");
                if (err.status_code === 409) {
                  console.log('Attachment upload conflict, retry.');
                  addAttachment(req, res);
                  return;
                }
                else {
                  console.log("Unrecoverable error in upload", err);
                  clearTmp();
                  return error(err);
                }
              }
    
              clearTmp();
              ....
    }
    hellboy81
    @hellboy81
    OK, should I handle event "Upload attachment completed" in callback , not in in attachment.on('end',...)
    Why?
    Dominique Sandoz
    @streunerlein
    hm not sure, I never got lucky using on('end', ...)
    also because there are two/three different approaches and i think it had to do with some API changes in streams in node and as well as modules can do it differently
    so i would suggest you to use the variant above, where nano handles it the way it wants
    hellboy81
    @hellboy81
    Only in callback I can get response from CouchDB?
    Dominique Sandoz
    @streunerlein
    yes
    hellboy81
    @hellboy81
    In `on 'end'' this information is not available?
    It's celar
    Dominique Sandoz
    @streunerlein
    when you get the response from CouchDB, it means streaming was ok, then of course, CouchDB errors can occur, but they have nothing to do with the streaming, that's why you have to check err in the callback
    @hellboy81 i have no idea, i just remember that dealing with on('end', ...) was not successful that time i wrote that code
    hellboy81
    @hellboy81
    I must handle only 409 (Conflict error)
    ?
    Dominique Sandoz
    @streunerlein
    you don't, but you can. It can happen, in my app it's quite frequent because there are many writes happening. But usually, Conflict is rare
    But a good programmer handles it in one way or the other ;)
    (my strategy here is to refetch the document to get the latest revision and try again to upload, as long until it works, may not be the best for all applications)
    for "making it work", you don't need to handle 409. Handle it when the problem gets frequent
    hellboy81
    @hellboy81
    OK, which kind of error expecting 409 can happens?
    Dominique Sandoz
    @streunerlein
    that has to do with CouchDBs conflict/revision system
    hellboy81
    @hellboy81
    I think Idea with upload retry is not suitable 4 me
    Dominique Sandoz
    @streunerlein
    read about it in the docs, it can also happen when you update the doc elsewhere
    ok then just go for it and not handle 409 that's perfectly fine
    hellboy81
    @hellboy81
    OK, its clear, In body object from uploaded handler is returned the most actual revison of the document
    Isn't it?
    wir können auch Deutsch sprechen ;-)
    Dominique Sandoz
    @streunerlein
    yes, it is - but in case of an error, body will be null
    No, let's go with english, as this is a public channel and other people may want to profit from our discussion
    aber danke :)
    hellboy81
    @hellboy81
    Jetzt alle müssen Deutsch lernen ;-)
    Habe noch eine Frage: wenn db.insert ein nicht-leereserr - Objekt zurückgibt, dies bedeutet automatisch, dass ok == false und umgekehrt kein Error - ok ist immer true
    ?
    Dominique Sandoz
    @streunerlein
    @hellboy81 I'll gladly answer your questions when you state it in english :)
    *them
    hellboy81
    @hellboy81

    OK, at the moment I have following problem:

    I am trying to implement attachment upload in the right way.

    As I mentioned I should do it in following steps

    • db.get - Get document (existing or not existing)
      • db.insert - If document not exists
    • db.attachment.insert - Insert attachment
      • If attachment upload success:
        - db.get to get the updated versions (with `_attachments`)
        - Add additional custom attachment meta data to the document 
        - db.insert - Save updated document

    Can you verify it?

    hellboy81
    @hellboy81
    @streunerlein
    hellboy81
    @hellboy81
    OK, As I mentioned I should ALWAYS handle 409 error (Document update conflict)
    hellboy81
    @hellboy81
    dscape/nano#295
    Is there db.attachment.head implementation?
    steinfernandez
    @steinfernandez
    Hello - could someone clarify the right way to pass the params argument to db.view? Nothing I try seems to be working - I always get the unfiltered results of the view. Thanks!
    steinfernandez
    @steinfernandez
    passing it as { key:[username]} managed to filter out literally everything including the relevant results, which is different but not quite what i want
    Steven Van Eenoo
    @StevenVanEenoo
    Since v6.x passing in a url requires it to be https? Therefor require('nano')('http://localhost:5984/foo'); fails. Is this the expected behavior and we should all use https now?
    Guido Villaverde
    @limoragni
    Hello everyone! Anyone know how can I logout from couchdb. In the docs it says how to login using nano.auth. But there's nothing about loging out
    Tri Nguyen
    @tnguyen14
    does nano support a promise-based interface?