Skip to content

Instantly share code, notes, and snippets.

@joselcvarela
Last active March 17, 2025 06:47
Show Gist options
  • Save joselcvarela/71343f2a055093b94e41562b4dd71244 to your computer and use it in GitHub Desktop.
Save joselcvarela/71343f2a055093b94e41562b4dd71244 to your computer and use it in GitHub Desktop.
var ip = "localhost"
var dbName = "DBNAME"
var viewType = "VIEWTYPE"
var viewName = "VIEWNAME"
$.getJSON("http://"+ip+":5984/"+dbName+"/_design/"+viewType+"/_view/"+viewName+"/", function(data) {
    data.rows.forEach(function (doc) {
var __id = doc.value._id
delete doc.value._id
var newDoc = doc.value
newDoc.values = Object.assign({}, doc.value.values, {newValue: false})
$.ajax({
dataType: 'json',
data: JSON.stringify(newDoc),
            url: "http://"+ip+":5984/"+dbName+"/" + __id,
            type: 'PUT',
            success: function(result) {
                console.log("Updated document with id " + __id);
            }
        });
    });
});

Comments are disabled for this gist.