简体   繁体   中英

How to migrate DOWN the MongoDB

I am using migrate-mongo library. I need to add some users to the application, so my colleagues can start working on it. My migrate up, is adding the users as expected, but the DOWN is not working. Well, actually, when I run the DOWN, nothing happens and I receive no error whatsoever.

My package.json:

"migrate": "cd database && node index.js"

Content of the migration file itself:

module.exports = {
  async up(db) {
    await db.collection('users').insertOne({
      'email':'ps@ps.com',
      'password':'$2a$10$VP6BKllje64JwyKU3.lBYumjjRQVvPsW/A5W9/XqleiDg4C1tZaB2',
      'name':'Hanah',
      'role': 'Content'
    });

    await db.collection('users').insertOne({
      'email':'wex@wex.com',
      'password':'$2a$10$VP6BKllje64JwyKU3.lBYumjjRQVvPsW/A5W9/XqleiDg4C1tZaB2',
      'name':'Vedran',
      'role': 'CustomerService'
    });
  },

  async down(db) {
    await db.collection('users').deleteOne({'email': 'ps@ps.com'});
    await db.collection('users').deleteOne({'email': 'wex@wex.com'});
  },
};

I have followed the authors procedure how to create generic files.

What is wrong?

Not sure if this will help, but I have used the following syntax to remove fields successfully:

async down(db) {
    await db.collection('users').updateOne({'email': 'ps@ps.com'}, $unset: {'email': ''});
    await db.collection('users').updateOne({'email': 'wex@wex.com'}, $unset: {'email': ''});
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM