code: function validateDuplicateName(cb) {
      var themeId = themeData._id;
      var themeName = themeData.name;
  
      if (!themeName) {
        return cb(new Error("No theme name passed."));
      }
  
      var query = {};
  
      //If there is a theme id, then the query to the theme model must exclude the current theme id that is being updated.
      if (themeId) {
        query.name = themeName;
        //Excluding the themeId that is being updated.
        query["_id"] = {"$nin": [themeId]};
      } else { //Just checking that the theme name exists as a theme is being created
        query.name = themeName;
      }
  
      themeModel.count(query, function(err, count) {
        if (err) {
          return cb(err);
        }
  
        //If the number of found theme is > 0, then there is another theme with the same name. Do not save the theme.
        if (count > 0) {
          return cb(new Error("Theme with name " + themeName + " already exists."));
        } else {//No duplicates, can proceed with saving the theme.
          return cb();
        }
      });
    }
docs: Validating theme duplicate names.