lib/data-store/index.js
function save (dataStore, collectionName, resources, callback) {
  // Open the data store
  dataStore.__openDataStore(collectionName, (err, existingResources) => {
    if (err) {
      return callback(err);
    }

    resources.forEach((resource) => {
      // Set the timestamp properties
      let now = Date.now();
      resource.createdOn = new Date(now);
      resource.modifiedOn = new Date(now);

      // Does the resource already exist?
      let existing = _.find(existingResources, resource.filter(dataStore.__router));
      if (existing) {
        // Merge the new data into the existing resource
        util.debug("%s already exists. Merging new data with existing data.", resource.toString());
        existing.merge(resource);

        // Update the calling code's reference to the resource
        _.extend(resource, existing);
      }
      else {
        existingResources.push(resource);
      }
    });

    // Save the changes
    dataStore.__saveDataStore(collectionName, existingResources, (err) => {
      callback(err, resources);
    });
  });
}
function save (dataStore, collectionName, resources, callback) {
  // Open the data store
  dataStore.__openDataStore(collectionName, (err, existingResources) => {
    if (err) {
      return callback(err);
    }

    resources.forEach((resource) => {
      // Set the timestamp properties
      let now = Date.now();
      resource.createdOn = new Date(now);
      resource.modifiedOn = new Date(now);

      // Does the resource already exist?
      let existing = _.find(existingResources, resource.filter(dataStore.__router));
      if (existing) {
        // Merge the new data into the existing resource
        util.debug("%s already exists. Merging new data with existing data.", resource.toString());
        existing.merge(resource);

        // Update the calling code's reference to the resource
        _.extend(resource, existing);
      }
      else {
        existingResources.push(resource);
      }
    });

    // Save the changes
    dataStore.__saveDataStore(collectionName, existingResources, (err) => {
      callback(err, resources);
    });
  });
}
function save ( dataStore , collectionName , resources , callback ) { // Open the data store dataStore . __openDataStore ( collectionName , ( err , existingResources ) => { if ( err ) { return callback ( err ) ; } resources . forEach ( ( resource ) => { // Set the timestamp properties let now = Date . now ( ) ; resource . createdOn = new Date ( now ) ; resource . modifiedOn = new Date ( now ) ; // Does the resource already exist? let existing = _ . find ( existingResources , resource . filter ( dataStore . __router ) ) ; if ( existing ) { // Merge the new data into the existing resource util . debug ( "%s already exists. Merging new data with existing data." , resource . toString ( ) ) ; existing . merge ( resource ) ; // Update the calling code's reference to the resource _ . extend ( resource , existing ) ; } else { existingResources . push ( resource ) ; } } ) ; // Save the changes dataStore . __saveDataStore ( collectionName , existingResources , ( err ) => { callback ( err , resources ) ; } ) ; } ) ; }
Saves the given resources to the data store.
If any of the resources already exist, the new data is merged with the existing data.

@param   {DataStore}     dataStore      - The DataStore to operate on
@param   {string}        collectionName - The collection that all the resources belong to
@param   {Resource[]}    resources      - The Resources to be saved
@param   {function}      callback       - Callback function
Saves the given resources to the data store . If any of the resources already exist the new data is merged with the existing data .