2014-06-08 2 views
0

업데이트 기능을 사용하여 couchdb에 첨부 파일을 어떻게 추가합니까? 저의 couchapp에서는 데이터베이스와의 모든 상호 작용을 통해 더 나은 보안을 위해 쇼, 목록 및 업데이트 기능을 수행하고자합니다.업데이트 기능을 사용하여 couchdb에 첨부 파일 추가하기

업데이트 기능이있는 첨부 파일을 삭제할 수 있다고 생각합니다 (직접 _attachments 필드를 직접 업데이트해야한다고 생각하지 않지만). 내가 사용하고 있습니다 :

function(doc, req){ 
    if (doc) { 
     delete doc._attachments[req.form.filename]; 
     return [doc, JSON.stringify(doc)]; 
    } 
    else { 
     return [null, "Document does not exist."]; 
    } 
} 

감사

답변

1

을 당신은 쉬운 업데이트 기능에서 새 첨부 파일을 추가 할 수 있습니다 - 다만 inline를 문서의 몸으로 :

function(doc, req){ 
    if (doc) { 
     // attachment delete 
     delete doc._attachments[req.form.filename]; 
     // add another one 
     doc._attachments.hello = { 
      "content_type": "text/plain", // required 
      "data": "d29ybGQ=" //world 
     } 
     return [doc, JSON.stringify(doc)]; 
    } 
    else { 
     return [null, "Document does not exist."]; 
    } 
} 
관련 문제