{"record":{"id":"9bd6eed51cac2b2f","repo":"apache/beam","slug":"error-executing-splitvector-command-w","errorCode":null,"errorMessage":"error executing splitVector command: %w","messagePattern":"error executing splitVector command: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/io/mongodbio/id_range_split.go","lineNumber":216,"sourceCode":") ([]documentID, error) {\n\tdatabase := collection.Database()\n\tnamespace := fmt.Sprintf(\"%s.%s\", database.Name(), collection.Name())\n\n\tcmd := bson.D{\n\t\t{Key: \"splitVector\", Value: namespace},\n\t\t{Key: \"keyPattern\", Value: bson.D{{Key: \"_id\", Value: 1}}},\n\t\t{Key: \"min\", Value: bson.D{{Key: \"_id\", Value: outerRange.Min}}},\n\t\t{Key: \"max\", Value: bson.D{{Key: \"_id\", Value: outerRange.Max}}},\n\t\t{Key: \"maxChunkSizeBytes\", Value: maxChunkSizeBytes},\n\t}\n\n\topts := options.RunCmd().SetReadPreference(readpref.Primary())\n\n\tvar result struct {\n\t\tSplitKeys []documentID `bson:\"splitKeys\"`\n\t}\n\tif err := database.RunCommand(ctx, cmd, opts).Decode(&result); err != nil {\n\t\treturn nil, fmt.Errorf(\"error executing splitVector command: %w\", err)\n\t}\n\n\treturn result.SplitKeys, nil\n}\n\nfunc idRangesFromSplits(splitKeys []documentID, outerRange idRange) []idRange {\n\tsubRanges := make([]idRange, len(splitKeys)+1)\n\n\tfor i := 0; i < len(splitKeys)+1; i++ {\n\t\tsubRange := idRange{}\n\n\t\tif i == 0 {\n\t\t\tsubRange.Min = outerRange.Min\n\t\t\tsubRange.MinInclusive = outerRange.MinInclusive\n\t\t} else {\n\t\t\tsubRange.Min = splitKeys[i-1].ID\n\t\t\tsubRange.MinInclusive = true\n\t\t}","sourceCodeStart":198,"sourceCodeEnd":234,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/io/mongodbio/id_range_split.go#L198-L234","documentation":"getSplitKeys runs the splitVector database command on the admin/database to compute _id split points for a collection. When RunCommand fails to execute or decode, the error is wrapped as 'error executing splitVector command'. splitVector is typically restricted (often to mongos/admin contexts), so this commonly indicates an unsupported or unauthorized command.","triggerScenarios":"splitVectorSplits calls getSplitKeys; database.RunCommand(ctx, {splitVector: ...}) fails — the command is not available on the target topology (e.g. standalone replica member via certain drivers/versions), the user lacks permission, maxChunkSizeBytes arg is invalid, or a network/context failure occurs.","commonSituations":"Running against standalone or Atlas instances where splitVector is not permitted for regular users; insufficient privileges (command normally reserved for sharding internals); wrong namespace or key pattern in the command; context deadline exceeded.","solutions":["Check the wrapped cause for an 'unauthorized'/'command not found' server error and fall back to the bucketAuto strategy","Grant the user the necessary role (splitVector is usually admin/sharding-only)","Verify the namespace and keyPattern passed to splitVector are correct","Ensure the command targets a mongos or shard that permits splitVector; avoid it on restricted managed services","Retry if the cause is a transient network error"],"exampleFix":"// before — Atlas user cannot run splitVector\nsplits, err := splitVectorSplits(ctx, db, coll, r, n, bundle)\n// after — choose bucketAuto fallback when splitVector is rejected\nif strings.Contains(err.Error(), \"not authorized\") {\n\tsplits, err = bucketAutoSplits(ctx, coll, r, n, bundle)\n}","handlingStrategy":"fallback","validationCode":"// probe splitVector availability\nerr := db.RunCommand(ctx, bson.D{{Key:\"splitVector\", Value: ns}, {Key:\"keyPattern\", Value: bson.M{\"_id\":1}}, {Key:\"maxChunkSizeBytes\", Value:1}}).Err()","typeGuard":null,"tryCatchPattern":"splits, err := splitVectorSplits(ctx, db, coll, r, n, bundle)\nif err != nil {\n\tsplits, err = bucketAutoSplits(ctx, coll, r, n, bundle)\n}","preventionTips":["Default to bucketAuto unless the topology is known to allow splitVector","Use a user with sharding/admin roles when splitVector is required","Validate namespace and keyPattern before issuing the command","Set a short timeout so fallback triggers quickly"],"tags":["mongodb","go","splitvector","split"],"backgroundTag":"database-query-failed","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}