Mongoose.js: remove collection or DB

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

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

6条回答
  •  猫巷女王i
    2020-11-30 09:05

    If want to drop collection after tests and your test were running in a docker container:

    mongoose = require("mongoose");
    ...
    afterAll(async () => {
      const url = 'mongodb://host.docker.internal:27017/my-base-name';
      await mongoose.connect(url)
      await mongoose.connection.collection('collection-name').drop()
    })
    

提交回复
热议问题