BUG: Node driver does not use indexes created with MongoDB compass (proof)!

For the moment I’ve tried this using MongoDB Compass 1.39.3, mongosh 1.10.6 and Node.js driver v6.0.0 and performed the following:

  1. Connect to serverless instance via Compass
  2. Create new collection
  3. Insert 5 documents
  4. Create index
  5. Connect to serverless cluster via mongosh
  6. Verify index exists
  7. Try filtering for 1 document and generating an explain plan to verify the index is used (it is)
  8. Create a Node.js script to validate the same operation uses the index (it does)

At the moment everything appear to be working as expected. If it helps the script I used in Node is:

const { MongoClient } = require("mongodb");
const client = new MongoClient("mongodb+srv://xyz.mongodb.net/");
async function run() {
  try {
    await client.connect();
    const database = client.db("test");
    const coll = database.collection("amplify");    
    var result = await coll.find({ amplify_id: 1 }).explain();
    console.log(result);
  } finally {
    await client.close();
  }
  process.exit(0);
}
run().catch(console.dir);
3 Likes