crazyones110
2/17/2020 - 4:02 AM

mongoose连接mongo

const mongoose = require('mongoose')

// ES6
mongoose.Promise = global.Promise

// Connect to the db before tests run
before(done => {
  // Connect to mongodb
  mongoose.connect('mongodb://localhost/testaroo', {
    useNewUrlParser: true,
    useUnifiedTopology: true
  })

  mongoose.connection
    .once('open', () => {
      console.log('Connection has been made, now make fireworks')
      done()
    })
    .on('error', error => {
      console.log('Connection error:', error)
    })
})

// Drop the characters collections before each test
beforeEach(done => {
  // Drop the collection
  mongoose.connection.collections.mariochars.drop(() => {
    done()
  })
})