Mongoose.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:
- «Mongoose» this
Removes the model named name
from the default connection, if it exists. You can use this function to clean up any models you created in your tests to prevent OverwriteModelErrors.
Equivalent to mongoose.connection.deleteModel(name)
.
Example:
mongoose.model('User', new Schema({ name: String }));
console.log(mongoose.model('User')); // Model object
mongoose.deleteModel('User');
console.log(mongoose.model('User')); // undefined
// Usually useful in a Mocha `afterEach()` hook
afterEach(function() {
mongoose.deleteModel(/.+/); // Delete every model
});
当前内容版权归 mongoosejs 或其关联方所有,如需对内容或内容相关联开源项目进行关注与资助,请访问 mongoosejs .