How to use the @lykmapipo/mongoose-common.toCollectionName function in @lykmapipo/mongoose-common

To help you get started, we’ve selected a few @lykmapipo/mongoose-common examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github lykmapipo / mongoose-gridfs / lib / bucket.js View on Github external
function createModel(optns, ...plugins) {
  // ensure options
  let { connection, modelName, bucketName } = _.merge({}, optns);
  connection = (connection || mongoose.connection);
  modelName = (_.isEmpty(modelName) ? DEFAULT_BUCKET_MODEL_NAME : modelName);
  bucketName = toCollectionName(modelName);
  bucketName =
    (modelName === DEFAULT_BUCKET_MODEL_NAME ? DEFAULT_BUCKET_NAME : bucketName);

  // create bucket
  const options =
    _.merge({}, { connection, modelName, bucketName }, optns);
  const bucket = createBucket(options);

  // construct file schema
  const schema = createFileSchema(bucket);

  // apply schema plugins with model options
  const schemaOptions = _.merge({}, schema.options);
  _.forEach([...plugins], plugin => {
    schema.plugin(plugin, schemaOptions);
  });