| 29 | } |
| 30 | |
| 31 | export function isSharded(topologyOrServer?: Topology | Server | Connection): boolean { |
| 32 | if (topologyOrServer == null) { |
| 33 | return false; |
| 34 | } |
| 35 | |
| 36 | if (topologyOrServer.description && topologyOrServer.description.type === ServerType.Mongos) { |
| 37 | return true; |
| 38 | } |
| 39 | |
| 40 | // NOTE: This is incredibly inefficient, and should be removed once command construction |
| 41 | // happens based on `Server` not `Topology`. |
| 42 | if (topologyOrServer.description && topologyOrServer.description instanceof TopologyDescription) { |
| 43 | const servers: ServerDescription[] = Array.from(topologyOrServer.description.servers.values()); |
| 44 | return servers.some((server: ServerDescription) => server.type === ServerType.Mongos); |
| 45 | } |
| 46 | |
| 47 | return false; |
| 48 | } |