Mongoose.js:删除集合或数据库 [英] Mongoose.js: remove collection or DB
本文介绍了Mongoose.js:删除集合或数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以使用mongoose.js删除集合或整个数据库?
Is it possible to remove collection or entire db using mongoose.js?
推荐答案
是的,尽管您是通过本机MongoDB驱动程序而不是通过Mongoose本身完成的.假设必需的,已连接的mongoose
变量是本机 Db
可通过mongoose.connection.db
访问该对象,并且该对象提供 dropCollection
和 dropDatabase
方法.
Yes, although you do it via the native MongoDB driver and not Mongoose itself. Assuming a required, connected, mongoose
variable, the native Db
object is accessible via mongoose.connection.db
, and that object provides dropCollection
and dropDatabase
methods.
// Drop the 'foo' collection from the current database
mongoose.connection.db.dropCollection('foo', function(err, result) {...});
// Drop the current database
mongoose.connection.db.dropDatabase(function(err, result) {...});
这篇关于Mongoose.js:删除集合或数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文