Uploaded image for project: 'CouchDB'
  1. CouchDB
  2. COUCHDB-1612

Transform all documents at once

Details

    • Wish
    • Status: Closed
    • Minor
    • Resolution: Won't Fix
    • None
    • None
    • Futon
    • None

    Description

      Sometimes, I would like to modify all documents at once...

      I use this function (jQuery, jquery.couchdb and Underscore necessary):

      function actionAllTransform(transform, commit) {
      // First get all documents:
      jQuery.couch.db(dbname).allDocs({
      include_docs: true,
      success: function(data) {
      data = _.map(data.rows, function(v)

      { return v.doc; }

      );
      // Remove the design documents
      data = _.filter(data, function(doc)

      { return (doc._id.substring(0,8) != "_design/"); }

      );

      // transform each document by a "transform" function
      data = _.map(data, transform);

      // If the function gave back null value, filter them out (they are considered as not modified)
      data = _.filter(data, function(doc)

      { return (doc != null); }

      );

      if (data.length == 0)

      { // no record left, nothing to do... return 0; }

      var bulk =

      { all_or_nothing: true, docs: data }

      ;

      // Check the result
      console.log(bulk);
      if (typeof(commit) == 'undefined')
      return

      // If commit, save the bulk in the db
      if (commit) {
      jQuery.couch.db(dbname).bulkSave(bulk, {
      success: function()

      { // youpee, it worked }

      });
      }
      }
      });
      };

      As far as I understand, the question is to be able to put that function in the futon interface... and render results in the same styleguide than the other panels.

      Attachments

        Activity

          People

            ryanramage Ryan Ramage
            jehon jean honlet
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Slack

                Issue deployment