function doRemoveDatasetClientWithRecords(datasetClientId, cb) {
  debug('doRemoveDatasetClientWithRecords datasetClientId = %s',  datasetClientId);
  async.waterfall([
    async.apply(doReadDatasetClient, datasetClientId),
    function removeRefs(datasetClientJson, next) {
      var datasetId = datasetClientJson.datasetId;
      var recordsCollection = mongoClient.collection(getDatasetRecordsCollectionName(datasetId));
      recordsCollection.updateMany({'refs': datasetClientId}, {'$pull': {'refs': datasetClientId}}, function(err) {
        return next(err, datasetClientJson);
      });
    },
    function deleteDatasetClient(datasetClientJson, next) {
      var col = mongoClient.collection(DATASETCLIENTS_COLLECTION);
      col.findOneAndDelete({'id': datasetClientId}, next);
    }
  ], function(err, result) {
    if (err) {
      debug('Failed to doRemoveDatasetClientWithRecords due to error %s', err);
      return cb(err);
    } else {
      return cb(null, result && result.value);
    }
  });
}
function doRemoveDatasetClientWithRecords(datasetClientId, cb) {
  debug('doRemoveDatasetClientWithRecords datasetClientId = %s',  datasetClientId);
  async.waterfall([
    async.apply(doReadDatasetClient, datasetClientId),
    function removeRefs(datasetClientJson, next) {
      var datasetId = datasetClientJson.datasetId;
      var recordsCollection = mongoClient.collection(getDatasetRecordsCollectionName(datasetId));
      recordsCollection.updateMany({'refs': datasetClientId}, {'$pull': {'refs': datasetClientId}}, function(err) {
        return next(err, datasetClientJson);
      });
    },
    function deleteDatasetClient(datasetClientJson, next) {
      var col = mongoClient.collection(DATASETCLIENTS_COLLECTION);
      col.findOneAndDelete({'id': datasetClientId}, next);
    }
  ], function(err, result) {
    if (err) {
      debug('Failed to doRemoveDatasetClientWithRecords due to error %s', err);
      return cb(err);
    } else {
      return cb(null, result && result.value);
    }
  });
}
function doRemoveDatasetClientWithRecords ( datasetClientId , cb ) { debug ( 'doRemoveDatasetClientWithRecords datasetClientId = %s' , datasetClientId ) ; async . waterfall ( [ async . apply ( doReadDatasetClient , datasetClientId ) , function removeRefs ( datasetClientJson , next ) { var datasetId = datasetClientJson . datasetId ; var recordsCollection = mongoClient . collection ( getDatasetRecordsCollectionName ( datasetId ) ) ; recordsCollection . updateMany ( { 'refs' : datasetClientId } , { '$pull' : { 'refs' : datasetClientId } } , function ( err ) { return next ( err , datasetClientJson ) ; } ) ; } , function deleteDatasetClient ( datasetClientJson , next ) { var col = mongoClient . collection ( DATASETCLIENTS_COLLECTION ) ; col . findOneAndDelete ( { 'id' : datasetClientId } , next ) ; } ] , function ( err , result ) { if ( err ) { debug ( 'Failed to doRemoveDatasetClientWithRecords due to error %s' , err ) ; return cb ( err ) ; } else { return cb ( null , result && result . value ) ; } } ) ; }
Remove the datasetClient that matches the given datasetClientId, and also remove the references of the datasetClient from the records.
@param {String} datasetClientId
@param {Function} cb
Remove the datasetClient that matches the given datasetClientId and also remove the references of the datasetClient from the records .