{"record":{"id":"ee07296c8c19fa9f","repo":"dgraph-io/dgraph","slug":"found-multiple-nodes-with-id-s","errorCode":null,"errorMessage":"Found multiple nodes with ID: %s","messagePattern":"Found multiple nodes with ID: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"graphql/resolve/mutation.go","lineNumber":356,"sourceCode":"\t// \t\t\"Project_1\" : \"0x123\",\n\t// \t\t\"Column_2\" : \"0x234\"\n\t// }\n\t// As only Add and Update mutations generate queries using RewriteQueries,\n\t// qNameToUID map will be non-empty only in case of Add or Update Mutation.\n\tqNameToUID := make(map[string]string)\n\tfor key, result := range queryResultMap {\n\t\tcount := 0\n\t\ttyp := qNameToType[key]\n\t\tfor _, res := range result {\n\t\t\tif x.HasString(res.Types, typ) {\n\t\t\t\tqNameToUID[key] = res.Uid\n\t\t\t\tcount++\n\t\t\t}\n\t\t}\n\t\tif count > 1 {\n\t\t\t// Found multiple UIDs for query. This should ideally not happen.\n\t\t\t// This indicates that there are multiple nodes with same XIDs / UIDs. Throw an error.\n\t\t\terr = errors.New(fmt.Sprintf(\"Found multiple nodes with ID: %s\", qNameToUID[key]))\n\t\t\tgqlErr := schema.GQLWrapLocationf(\n\t\t\t\terr, mutation.Location(), \"mutation %s failed\", mutation.Name())\n\t\t\treturn emptyResult(gqlErr), resolverFailed\n\t\t}\n\t}\n\n\t// Create upserts, delete mutations, update mutations, add mutations.\n\tupserts, err = mr.mutationRewriter.Rewrite(ctx, mutation, qNameToUID)\n\n\tif err != nil {\n\t\treturn emptyResult(schema.GQLWrapf(err, \"couldn't rewrite mutation %s\", mutation.Name())),\n\t\t\tresolverFailed\n\t}\n\tif len(upserts) == 0 {\n\t\treturn &Resolved{\n\t\t\tData:       completeMutationResult(mutation, nil, 0),\n\t\t\tField:      mutation,\n\t\t\tErr:        nil,","sourceCodeStart":338,"sourceCodeEnd":374,"githubUrl":"https://github.com/dgraph-io/dgraph/blob/759e242be62c91f8d084da06ad0c8d21256d9c07/graphql/resolve/mutation.go#L338-L374","documentation":"During a mutation, an upsert/query block produced more than one UID for a single query name (qNameToUID counted >1 results). Since the node should be uniquely identified by its XID or UID, multiple matches indicate data corruption — duplicate nodes sharing the same external ID — so the mutation is aborted rather than silently modifying the wrong node.","triggerScenarios":"An update/delete mutation whose @id/XID filter matches more than one stored node; concurrent writes created two nodes with the same external identifier; the uniqueness check (count > 1) fires in rewriteAndExecute.","commonSituations":"Data imported before the @id/XID uniqueness enforcement was added; manual DQL writes bypassing GraphQL validation; a race in concurrent Add mutations inserting the same XID twice.","solutions":["Find and delete/merge the duplicate nodes sharing the same XID in the underlying Dgraph data","Run a data cleanup query listing all nodes for the offending XID to identify duplicates","Enforce XID uniqueness by re-adding the @id directive and cleaning legacy data","Re-run the mutation after de-duplication"],"exampleFix":"// before\nupsert(query: q(filter: { xid: { eq: \"dup-1\" } })) // matches 2 nodes\n// after\ncleanup duplicates so xid \"dup-1\" maps to exactly one node, then retry","handlingStrategy":"validation","validationCode":"// before updating, verify uniqueness\nconst dupes = await dqlQuery(`query q(filter: { xid: { eq: \"${xid}\" } }) { count }`);\nif (dupes.data.q.length > 1) throw new Error(`Found multiple nodes with ID: ${xid}`);","typeGuard":null,"tryCatchPattern":"try {\n  await updateMutation(input);\n} catch (err) {\n  if (err.message.startsWith('Found multiple nodes with ID:')) {\n    // run dedup cleanup for the reported ID before retrying\n  }\n}","preventionTips":["Always use @id directive with unique external IDs","Clean legacy imports for XID duplicates before enabling updates","Avoid manual DQL writes that bypass uniqueness","Monitor for duplicate-XID metrics/alerts"],"tags":["data-integrity","duplicate-nodes","mutation"],"backgroundTag":"duplicate-node-id","analyzedSha":"759e242be62c91f8d084da06ad0c8d21256d9c07","analyzedAt":"2026-09-01T14:42:12.034Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}