Open JoeySelahJr opened 3 years ago
Any update on this? We are facing the same issue.
I do not know if this specifically solves your problem, but I will leave it here.
I use the try{} catch(err){}
block and compare the error code in it
I use a different migration library, but I think the principle is clear to you
const collections = ['sessions', 'users'];
module.exports = {
async up(db) {
try {
await Promise.all(collections.map((name) => db.createCollection(name)));
} catch (err) {
if (err.codeName !== 'NamespaceExists') {
throw err;
}
}
},
async down(db) {
await Promise.all(collections.map((name) => db.collection(name).drop()));
},
};
I'm submitting a...
Current behavior
I'm trying to do db-migrate scripts for a mongo instance. I've created a really simple addIndex script as a test I run db-migrate up, it creates the migrations collection, it adds the index but no records are added to the migrations collection. db-migrate doesn't know it's ran the script. Second time I run db-migrate up, an error is thrown stating that the collection already exists.
Expected behavior
After running db-migrate up, the index is applied, the migrations collection is created with a document tracking what's been ran. The second time I run db-migrate up, nothing is applies since it's already been applied, and no errors occur.
Minimal reproduction of the problem with instructions
What is the motivation / use case for changing the behavior?
Can't use db-migration with mongo currently
Environment