Description
Issue description
I am struggling with using db-migrate with MongoDB.
Expected Behavior
I would like to see created index for specific field of my collection on mongodb by using db-migrate
Actual Behavior
[ERROR] AssertionError [ERR_ASSERTION]: ifError got unwanted exception: Unsupported OP_QUERY command: listCollections. The client driver may require an upgrade. For more details see https://dochub.mongodb.org/core/legacy-opcode-removal
at module.exports (/Users/cihataydin/Milvus/microservice-nestjs-template/node_modules/db-migrate/lib/commands/helper/assert.js:9:14)
at /Users/cihataydin/Milvus/microservice-nestjs-template/node_modules/db-migrate/lib/commands/up.js:29:16
at tryCatcher (/Users/cihataydin/Milvus/microservice-nestjs-template/node_modules/bluebird/js/release/util.js:16:23)
at Promise.errorAdapter [as _rejectionHandler0] (/Users/cihataydin/Milvus/microservice-nestjs-template/node_modules/bluebird/js/release/nodeify.js:35:34)
at Promise._settlePromise (/Users/cihataydin/Milvus/microservice-nestjs-template/node_modules/bluebird/js/release/promise.js:601:21)
at Promise._settlePromise0 (/Users/cihataydin/Milvus/microservice-nestjs-template/node_modules/bluebird/js/release/promise.js:649:10)
at Promise._settlePromises (/Users/cihataydin/Milvus/microservice-nestjs-template/node_modules/bluebird/js/release/promise.js:725:18)
at _drainQueueStep (/Users/cihataydin/Milvus/microservice-nestjs-template/node_modules/bluebird/js/release/async.js:93:12)
at _drainQueue (/Users/cihataydin/Milvus/microservice-nestjs-template/node_modules/bluebird/js/release/async.js:86:9)
at Async._drainQueues (/Users/cihataydin/Milvus/microservice-nestjs-template/node_modules/bluebird/js/release/async.js:102:5)
at Async.drainQueues [as _onImmediate] (/Users/cihataydin/Milvus/microservice-nestjs-template/node_modules/bluebird/js/release/async.js:15:14)
at process.processImmediate (node:internal/timers:478:21)
at MongoError.create (/Users/cihataydin/Milvus/microservice-nestjs-template/node_modules/mongodb-core/lib/error.js:31:11)
at queryCallback (/Users/cihataydin/Milvus/microservice-nestjs-template/node_modules/mongodb-core/lib/cursor.js:212:36)
at /Users/cihataydin/Milvus/microservice-nestjs-template/node_modules/mongodb-core/lib/connection/pool.js:469:18
at process.processTicksAndRejections (node:internal/process/task_queues:77:11)
Steps to reproduce
- Create database.json file
{
"mongo": {
"migrationsTableName": "_migrations",
"driver": "mongodb",
"host": {"ENV": "DATABASE_HOST"},
"port": {"ENV": "DATABASE_PORT"},
"username": {"ENV": "DATABASE_USERNAME"},
"password": {"ENV": "DATABASE_PASSWORD"},
"authSource": {"ENV": "DATABASE_AUTH_SOURCE"},
"authMechanism": "DEFAULT",
"database": "test",
"multipleStatements": true,
"migrationsDir": "migrations",
"useNewUrlParser": true,
"useUnifiedTopology": true
}
}
- Create migration file
db-migrate create mongo-index-test --config database.json -e mongo
- Fill the up and down functions
const { MongoClient } = require("mongodb");
exports.up = async function(db) {
const client = await MongoClient.connect(db.connectionString);
const database = client.db('test');
await database.collection('examples').createIndex({ name: 1 }, { name: 'test_index' });
await client.close();
};
exports.down = async function(db) {
const client = await MongoClient.connect(db.connectionString);
const database = client.db('test');
await database.collection('examples').dropIndex('test_index');
await client.close();
};
- Run migrations
db-migrate up --config database.json -e mongo
My Environment
Operating System macOS Monterey version 12.5
Node.js version 20.8.0
Typescript version 5.2.2
db-migrate 0.11.14
db-migrate-mongodb 1.5.0
mongodb driver version 6.2.0
docker container with mongodb version 7.0.1
Note: If I use Docker container with MongoDB version 5.0, the error will disappear, and the migration will work well.