Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AssertionError [ERR_ASSERTION]: ifError got unwanted exception: Unsupported OP_QUERY command: listCollections. #56

Open
cihataydin opened this issue Nov 13, 2023 · 0 comments

Comments

@cihataydin
Copy link

cihataydin commented Nov 13, 2023

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

  1. 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
  }
}
  1. Create migration file
    db-migrate create mongo-index-test --config database.json -e mongo
  2. 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();
};
  1. 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant