jstests/libs/fixture_helpers.js
/**
     * Returns the number of shards that 'coll' has any chunks on. Returns 1 if the collection is
     * not sharded. Note that if the balancer is enabled then the number of shards with chunks for
     * this collection can change at any moment.
     */
Returns the number of shards that 'coll' has any chunks on. Returns 1 if the collection is
not sharded. Note that if the balancer is enabled then the number of shards with chunks for
this collection can change at any moment.
Returns the number of shards that ' coll ' has any chunks on . Returns 1 if the collection is not sharded . Note that if the balancer is enabled then the number of shards with chunks for this collection can change at any moment .
function numberOfShardsForCollection(coll) {
        if (!isMongos(coll.getDB()) || !isSharded(coll)) {
            return 1;
        }
        const collMetadata =
            db.getSiblingDB("config").collections.findOne({_id: coll.getFullName()});
        if (collMetadata.timestamp) {
            return db.getSiblingDB("config")
                .chunks.distinct("shard", {uuid: collMetadata.uuid})
                .length;
        } else {
            return db.getSiblingDB("config")
                .chunks.distinct("shard", {ns: coll.getFullName()})
                .length;
        }
    }
function numberOfShardsForCollection ( coll ) { if ( ! isMongos ( coll . getDB ( ) ) || ! isSharded ( coll ) ) { return 1 ; } const collMetadata = db . getSiblingDB ( "config" ) . collections . findOne ( { _id : coll . getFullName ( ) } ) ; if ( collMetadata . timestamp ) { return db . getSiblingDB ( "config" ) . chunks . distinct ( "shard" , { uuid : collMetadata . uuid } ) . length ; } else { return db . getSiblingDB ( "config" ) . chunks . distinct ( "shard" , { ns : coll . getFullName ( ) } ) . length ; } }
Returns the number of shards that 'coll' has any chunks on.
Returns the number of shards that ' coll ' has any chunks on .
// If we're not talking to a mongos, or the collection is not sharded, there is one // shard.