{"record":{"id":"79f1c8e1e594692a","repo":"googleapis/mcp-toolbox","slug":"error-populating-project-payload-s","errorCode":null,"errorMessage":"error populating project payload: %s","messagePattern":"error populating project payload: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/tools/mongodb/mongodbfind/mongodbfind.go","lineNumber":156,"sourceCode":"\tlogger, err := util.LoggerFromContext(ctx)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\topts := options.Find()\n\n\tsort := bson.M{}\n\tfor _, p := range sortParameters {\n\t\tsort[p.GetName()] = paramsMap[p.GetName()]\n\t}\n\topts = opts.SetSort(sort)\n\n\tif len(projectPayload) > 0 {\n\n\t\tresult, err := parameters.PopulateTemplateWithJSON(\"MongoDBFindProjectString\", projectPayload, paramsMap)\n\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"error populating project payload: %s\", err)\n\t\t}\n\n\t\tvar projection any\n\t\terr = bson.UnmarshalExtJSON([]byte(result), false, &projection)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"error unmarshalling projection: %s\", err)\n\t\t}\n\n\t\topts = opts.SetProjection(projection)\n\t\tlogger.DebugContext(ctx, fmt.Sprintf(\"Projection is set to %v\", projection))\n\t}\n\n\tif limit > 0 {\n\t\topts = opts.SetLimit(limit)\n\t\tlogger.DebugContext(ctx, fmt.Sprintf(\"Limit is being set to %d\", limit))\n\t}\n\treturn opts, nil\n}","sourceCodeStart":138,"sourceCodeEnd":174,"githubUrl":"https://github.com/googleapis/mcp-toolbox/blob/8cc6e09de2ad7b8bffc77751799585a1401a48eb/internal/tools/mongodb/mongodbfind/mongodbfind.go#L138-L174","documentation":"During find-option construction, the tool renders the project payload template against the resolved parameters via parameters.PopulateTemplateWithJSON. If template rendering fails (malformed template syntax, missing parameters, invalid JSON payload), the error is wrapped as 'error populating project payload'. It indicates the projection template could not be produced from the supplied parameter values.","triggerScenarios":"Invoke() on a mongodb-find tool whose projectPayload contains template placeholders not present in paramsMap, or whose project payload is not valid JSON/template syntax.","commonSituations":"Referencing a parameter name in the project payload that isn't declared in the tool's parameters; JSON typos in the project string; auth参数-backed params absent at invocation time; clients sending incomplete parameter sets.","solutions":["Fix the project payload JSON/template syntax in the tool config.","Ensure every placeholder in the project payload matches a declared parameter.","Check the parameters sent by the client include all values the projection template needs."],"exampleFix":"// before\nproject: '{ \"name\": {{.params.name}} }'   // malformed template\n// after\nproject: '{ \"name\": 1, \"email\": 1 }'","handlingStrategy":"validation","validationCode":"// Go: verify every placeholder in the project payload has a matching param\nfor _, name := range extractPlaceholders(projectPayload) {\n    if _, ok := paramsMap[name]; !ok {\n        return fmt.Errorf(\"missing param %q for project payload\", name)\n    }\n}","typeGuard":null,"tryCatchPattern":"opts, err := getOptions(ctx, sortParams, projectPayload, limit, paramsMap)\nif err != nil && strings.Contains(err.Error(), \"error populating project payload\") {\n    // fall back: drop projection and query without it\n    opts, err = getOptions(ctx, sortParams, \"\", limit, paramsMap)\n}","preventionTips":["Keep projection payloads as static valid JSON when possible.","Declare every parameter referenced by the project template.","Test template rendering with sample param values before deployment."],"tags":["go","mongodb","template-rendering","projection"],"backgroundTag":"template-render-failed","analyzedSha":"8cc6e09de2ad7b8bffc77751799585a1401a48eb","analyzedAt":"2026-09-05T01:10:36.887Z","contentChangedAt":"2026-09-05T01:10:36.887Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}