node.js 및 request 모듈을 사용하십시오.
Pre : 대상 문서가 DB에 있습니다. 원본 첨부물이 DB에 존재합니다
var originAttachment = 'somefile.txt'
var originDocId = '1somecouchdbid';
var origindb = 'http://localhost:5984/db1';
var destinationAttachment = 'somefile.txt'
var destinationDocId = '2somecouchdbid';
var desinationdb = 'http://localhost:5984/db2';
var uridestination = desinationdb + "/" + destinationDocId;
request(uridestination, function(err, res, body){
if(err){
throw err;
}
var doc = JSON.parse(body);
var origin = origindb + '/' + originDocId + '/' + encodeURIComponent(originAttachment);
var optionsOrigin = {
url: origin
};
var uridestination = desinationdb + '/' + destinationDocId + '/' + encodeURIComponent(destinationAttachment) + '?rev=' + doc._rev;
var optionDestination = {
url: uridestination,
method: 'PUT',
headers: {
'Content-Type': false
}
};
request(optionsOrigin)
.pipe(request(optionsDestination, function(err, res, body){
if(err){
throw err;
}
console.log(body);
}));
});