I need to retrieve information about a MongoDB collection's sharding configuration, specifically the shardKey and unique fields. While I can easily obtain this information using the sh.status() command in the MongoDB shell, I haven't been able to figure out how to do this using the MongoDB Node.js driver.
Is it possible to retrieve this information using the Node.js driver, and if so, how can I do it?
I already tried collection.stats(), but no luck. There is a shards object in returned object value but fieds I need aren't there.
const client = await MongoClient.connect(uri);
const db = client.db(dbName);
const stats = await db.collection(collectionName).stats();
I'm not really sure what are the information you required by you can run the
adminCommandequivalent in nodejs usingrunCommande.g.
The list of commands u can run for sharding is here.