我需要为MongoDB数据库创建几个部署脚本,如数据迁移和fixture,我找不到有关如何使用Mongoose API删除索引的足够信息.使用官方MongoDB API时,这非常简单:
要删除指定集合上的所有索引:
db.collection.dropIndexes();
但是,我想使用Mongoose,我尝试使用executeDbCommand改编自这篇文章,但没有成功:
mongoose.connection.db.executeDbCommand({ dropIndexes: collectionName, index: '*' },
function(err, result) { /* ... */ });
Run Code Online (Sandbox Code Playgroud)
我应该使用官方MongoDB API for Node.js还是我错过了这种方法?