{"record":{"id":"4ff0475fe6466ecf","repo":"weaviate/weaviate","slug":"error-while-trying-to-find-shard-s-in-collection","errorCode":null,"errorMessage":"error while trying to find shard: %s in collection: %s","messagePattern":"error while trying to find shard: (.+?) in collection: (.+?)","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cluster/router/router.go","lineNumber":308,"sourceCode":"}\n\n// targetShards returns either all shards or a single one, depending on the value of the shard parameter.\nfunc (r *singleTenantRouter) targetShards(collection, shardName string) ([]string, error) {\n\tif shardName == \"\" {\n\t\treturn r.schemaReader.Shards(collection)\n\t}\n\n\t// Membership check only — avoids Shards' sorted copy of the full shard list on every routing-plan build.\n\tfound := false\n\terr := r.schemaReader.Read(collection, true, func(_ *models.Class, state *sharding.State) error {\n\t\t_, found = state.Physical[shardName]\n\t\treturn nil\n\t})\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tif !found {\n\t\treturn nil, fmt.Errorf(\"error while trying to find shard: %s in collection: %s\", shardName, collection)\n\t}\n\treturn []string{shardName}, nil\n}\n\n// readReplicasForShard gathers only read replicas for one shard.\nfunc (r *singleTenantRouter) readReplicasForShard(collection, tenant, shard string) ([]types.Replica, error) {\n\treplicas, err := r.schemaReader.ShardReplicas(collection, shard)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"error while getting replicas for collection %q shard %q: %w\", collection, shard, err)\n\t}\n\n\treadNodeNames := r.replicationFSMReader.FilterOneShardReplicasRead(collection, shard, replicas)\n\treturn buildReplicas(readNodeNames, shard, r.nodeSelector.NodeHostname), nil\n}\n\n// writeReplicasForShard gathers the write replicas for one shard.\nfunc (r *singleTenantRouter) writeReplicasForShard(collection, tenant, shard string) ([]types.Replica, error) {\n\treplicas, err := r.schemaReader.ShardReplicas(collection, shard)","sourceCodeStart":290,"sourceCodeEnd":326,"githubUrl":"https://github.com/weaviate/weaviate/blob/75aa4b6d11f8818305aafd4440b4e32794f7ca04/cluster/router/router.go#L290-L326","documentation":"targetShards walks the class's shards (physical or partitioned) looking for the requested shardName; if none matches, it returns this error. It means the shard simply is not part of the collection's shard set on this router, so no routing plan can be built.","triggerScenarios":"Directing a read/write at a shard name that does not exist for the collection — wrong shard name, shard deleted, tenant name used as shard name on a non-partitioned collection, or collection recreated with a different partitioning.","commonSituations":"Hand-built shard/tenant routing in scripts; requests after a tenant was offboarded and its shard removed; typos in shard identifiers; stale caches of shard names after a schema update.","solutions":["List actual shards (GET /v1/schema/{class}/shards) and use an existing shard name.","Verify tenant vs shard semantics: for MT collections use the tenant name; do not confuse tenant with physical shard.","Refresh schema/shard caches or reconnect — the shard set may have changed since the client cached it.","Recreate the shard/tenant if it was deleted unintentionally."],"exampleFix":"// before\ncur, err := client.Schema().Class().ShardGetter().WithShardName(\"shard-9\").Do(ctx) // nonexistent\n// after: enumerate first\nshards, _ := client.Schema().Class().ShardsGetter().Do(ctx)\n// pick a valid shard from shards","handlingStrategy":"validation","validationCode":"shards, err := client.Schema().Class().ShardsGetter().Do(ctx)\nif err != nil { return err }\nif !slices.Contains(shards, shardName) {\n  return fmt.Errorf(\"shard %q not in collection shards %v\", shardName, shards)\n}","typeGuard":null,"tryCatchPattern":"if strings.Contains(err.Error(), \"error while trying to find shard\") {\n  // re-list shards and pick a valid one, or recreate the tenant/shard\n}","preventionTips":["Always enumerate shards/tenants from the schema API rather than caching names.","Use tenant names (not shard names) for MT collections.","Handle shard deletion events in automation before issuing further requests."],"tags":["routing","shard","not-found","distributed"],"backgroundTag":"shard-not-found","analyzedSha":"75aa4b6d11f8818305aafd4440b4e32794f7ca04","analyzedAt":"2026-09-04T14:58:20.392Z","contentChangedAt":"2026-09-04T14:58:20.392Z","schemaVersion":2},"datasetVersion":"2026-09-11T21:17:09.523Z"}