text: const mongoose = require('mongoose')
  let CveIdSchema
  
  const schema = {
    _id: false,
    cve_id: String,
    cve_year: String,
    state: String,
    owning_cna: String,
    requested_by: {
      cna: String,
      user: String
    },
    reserved: Date,
    time: {
      created: Date,
      modified: Date
    }
  }
  
  if (process.env.POPULATE === 'true') {
    CveIdSchema = new mongoose.Schema(schema, { collection: 'Cve-Id' })
  } else {
    if (process.env.NODE_ENV === 'test') {
      schema.reserved = { type: Date, default: Date.now }
    }
  
    CveIdSchema = new mongoose.Schema(schema, { collection: 'Cve-Id', timestamps: { createdAt: 'time.created', updatedAt: 'time.modified' } })
  }
  
  CveIdSchema.query.byCveId = function (cveId) {
    return this.where({ cve_id: new RegExp('^' + cveId + '$', 'i') }) // match cveId exactly (case insensitive)
  }
  
  const CveId = mongoose.model('Cve-Id', CveIdSchema)
  
  module.exports = CveId
  