Guides  ›  CLI  ›  Migrate ← PREV NEXT →

Migrate

Add a migration, then run it from the project root.

// migrations/001-users.js
var { client } = require('@nodedk/mongodb')

module.exports = async function () {
  var connection = client('mongodb://127.0.0.1:27017')
  await connection.connect()
  try {
    await connection.db('example').collection('users')
      .createIndex({ email: 1 }, { unique: true })
  } finally {
    await connection.close()
  }
}
ndk migrate

Files run in filename order on every invocation. Make each migration safe to run again.

Next: Sitemap →

Tools for business systems.