Connection.prototype.deleteModel()

Parameters
  • name «String|RegExp» if string, the name of the model to remove. If regexp, removes all models whose name matches the regexp.
Returns:
  • «Connection» this

Removes the model named name from this connection, if it exists. You can use this function to clean up any models you created in your tests to prevent OverwriteModelErrors.

Example:

  1. conn.model('User', new Schema({ name: String }));
  2. console.log(conn.model('User')); // Model object
  3. conn.deleteModel('User');
  4. console.log(conn.model('User')); // undefined
  5. // Usually useful in a Mocha `afterEach()` hook
  6. afterEach(function() {
  7. conn.deleteModel(/.+/); // Delete every model
  8. });