MCPcopy
hub / github.com/mongodb/node-mongodb-native / validateLoadBalancedOptions

Function validateLoadBalancedOptions

src/connection_string.ts:560–581  ·  src/connection_string.ts::validateLoadBalancedOptions

* #### Throws if LB mode is true: * - hosts contains more than one host * - there is a replicaSet name set * - directConnection is set * - if srvMaxHosts is used when an srv connection string is passed in * * @throws MongoParseError

(
  hosts: HostAddress[] | string[],
  mongoOptions: MongoOptions,
  isSrv: boolean
)

Source from the content-addressed store, hash-verified

558 * @throws MongoParseError
559 */
560function validateLoadBalancedOptions(
561 hosts: HostAddress[] | string[],
562 mongoOptions: MongoOptions,
563 isSrv: boolean
564): void {
565 if (mongoOptions.loadBalanced) {
566 if (hosts.length > 1) {
567 throw new MongoParseError(LB_SINGLE_HOST_ERROR);
568 }
569 if (mongoOptions.replicaSet) {
570 throw new MongoParseError(LB_REPLICA_SET_ERROR);
571 }
572 if (mongoOptions.directConnection) {
573 throw new MongoParseError(LB_DIRECT_CONNECTION_ERROR);
574 }
575
576 if (isSrv && mongoOptions.srvMaxHosts > 0) {
577 throw new MongoParseError(class="st">'Cannot limit srv hosts with loadBalanced enabled');
578 }
579 }
580 return;
581}
582
583function setOption(
584 mongoOptions: any,

Callers 2

resolveSRVRecordFunction · 0.85
parseOptionsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected