Mongoose.js: remove collection or DB

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

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

6条回答
  •  眼角桃花
    2020-11-30 08:51

    For those that are using the mochajs test framework and want to clean all db collections after each test, you can use the following which uses async/await:

    afterEach(async function () {
      const collections = await mongoose.connection.db.collections()
    
      for (let collection of collections) {
        await collection.remove()
      }
    })
    

提交回复
热议问题