How to use the @lykmapipo/mongoose-common.Schema 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 / schema.js View on Github external
function createFileSchema(bucket) {
  // obtain collection name from bucket
  const collection = bucket.collectionName;

  // gridfs files collection compactible schema
  // see https://docs.mongodb.com/manual/core/gridfs/#the-files-collection
  const FileSchema = new Schema({
    length: { type: Number, index: true },
    chunkSize: { type: Number, index: true },
    uploadDate: { type: Date, index: true },
    md5: { type: String, trim: true, index: true, searchable: true },
    filename: { type: String, trim: true, index: true, searchable: true },
    contentType: { type: String, trim: true, index: true, searchable: true },
    aliases: { type: [String], sort: true, index: true, searchable: true },
    metadata: { type: Mixed },
  }, { collection, id: false, emitIndexErrors: true });

  // expose timestamps as virtuals
  FileSchema.virtual('createdAt').get(function () { return this.uploadDate; });
  FileSchema.virtual('updatedAt').get(function () { return this.uploadDate; });

  // allow virtuals to be included in toJSON and toObject
  FileSchema.set('toJSON', { virtuals: true });