docs: function(nodeId, mgmt, options) {
              var query;
              var oldNode;
              var self = this;
  
              return Promise.try(function() {
                  query = {node: nodeId, service: mgmt.service};
                  return self.find(query);
              })
              .then(function(mgmtSettings) {
                  assert.ok(mgmtSettings.length === 0 || mgmtSettings.length === 1,
                      "mgmts should be unique for a given node and service."
                  );
                  return _.first(mgmtSettings);
              })
              .tap(function() {
                  return waterline.nodes.getNodeById(nodeId)
                  .then(function(node) {
                      if(node) {
                          oldNode = node;
                      }
                  });
              })
              .then(function(mgmtSetting){
                  if(mgmtSetting){
                      assert.equal(mgmtSetting.node, nodeId,
                          "mgmtSetting does not match expected nodeId."
                      );
                      assert.equal(mgmtSetting.service, mgmt.service,
                          "mgmtSetting does not match expected service."
                      );
  
                      mgmtSetting.config = mgmt.config;
                      return self.updateOne(query, mgmt);
                  } else {
                      mgmt.node = nodeId;
                      return self.create(mgmt);
                  }
              })
              .then(function(mgmt) {
                  if (options && options.revealSecrets) {
                      return _revealSecrets(mgmt);
                  }
                  return mgmt;
              })
              .tap(function() {
                  if (oldNode) {
                      /* asynchronous, don't wait promise return for performance*/
                      waterline.nodes.getNodeById(oldNode.id)
                      .then(function (newNode) {
                          return eventsProtocol.publishNodeAttrEvent(oldNode, newNode, self.identity );//jshint ignore:line
                      })
                      .catch(function (error) {
                          logger.error('Error occurs', error);
                      });
                  }
              });
          }