Skip to content

fix: leave MongoDB query statements alone when normalizing SQL - #2401

Closed
evlawler wants to merge 1 commit into
mainfrom
feat/mongodb-query-normalization
Closed

evlawler wants to merge 1 commit into
mainfrom
feat/mongodb-query-normalization

Conversation

@evlawler

@evlawler evlawler commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor

The Node and Java agents are gaining sql_query events for MongoDB operations, with database_type: "mongodb" and a statement whose argument values are already placeholders:

db.users.updateOne({"_id": ?}, {"$set": {"name": ?}, "$inc": {"n": ?}})

normalizeSQL has no case for that database type, so the fallback obfuscation applies. It treats the quoted keys as string literals and a pair of $operators as a dollar-quoted string, and the statement above becomes db.users.updateOne({?: ?}, {?: {?: ?}, ?: {?: ?}}) in the sqlNormalized index, in the sequence diagram digest (through abstractSqlAstJSON, which falls back to normalizeSQL when the parser fails) and in change reports.

Fix. Return the statement unchanged for mongodb. analyzeSQL still returns null for it, so no tables are reported, which is the existing behavior for anything the SQL parser cannot read.

Test. sql.normalize.spec.js covers a known dialect, the fallback, and MongoDB statements passing through untouched.

Companion changes: getappmap/appmap-node#239 and getappmap/appmap-java#330 emit the events.

Written by Claude in a Claude Code session for Elizabeth Lawler. The commit carries Claude as author.

🤖 Generated with Claude Code

https://claude.ai/code/session_01LntddoBsqjRDRBepBx7oLZ

The Node and Java agents record MongoDB collection operations as
sql_query events with database_type "mongodb". Their "sql" is a
statement whose argument values are already replaced with placeholders:

  db.users.updateOne({"_id": ?}, {"$set": {"name": ?}, "$inc": {"n": ?}})

normalizeSQL had no case for that database type, so the fallback
obfuscation applied. It treats the quoted keys as string literals and a
pair of $operators as a dollar-quoted string, which turned the statement
above into `db.users.updateOne({?: ?}, {?: {?: ?}, ?: {?: ?}})` in the
sqlNormalized index and in change reports. Return the statement as it is
for that database type.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LntddoBsqjRDRBepBx7oLZ

Copy link
Copy Markdown
Contributor Author

Closing. This change only existed to let MongoDB statements pass through normalizeSQL for getappmap/appmap-node#239, and the discussion there concluded that recording Mongo operations as sql_query is not the right shape. The redesign will give non-SQL queries their own structure, so this patch is not needed.


Generated by Claude Code

@evlawler evlawler closed this Sep 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants