Mongoose.js: remove collection or DB

前端 未结 6 1985
遥遥无期
遥遥无期 2020-11-30 08:23

Is it possible to remove collection or entire db using mongoose.js?

6条回答
  •  旧巷少年郎
    2020-11-30 08:47

    Mongoose references the connection on every model. So, you may find it useful to also drop the DB or collection off of an individual model.

    For example:

    // Drop the 'foo' collection from the current database
    User.db.dropCollection('foo', function(err, result) {...});
    
    // Drop the current database
    User.db.dropDatabase(function(err, result) {...});
    

提交回复
热议问题