arXiv:2610.02770cs.CLOct 2026

Manuscript Offprint

arXiv:2610.02770

AptMQL-Bench: From Text-to-SQL to Text-to-MQL via Access-Pattern Schema Design and Data-Preserving Migration

Hy Nguyen, Nabi Rezvani, Robin Vujanic

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original. This text is shared under the same licence.

Abstract

Document databases such as MongoDB are core infrastructure for modern applications, and natural-language interfaces to them—text-to-MQL—would let non-experts query complex, semi-structured data without mastering the query language. Progress on this task depends on high-quality benchmarks, which are most practically obtained by converting an existing text-to-SQL benchmark to the document setting. Unfortunately, existing efforts rely on heuristics for mechanical conversion: the document schema mirrors the relational foreign-key graph, and each query mirrors its source SQL. As a result in our experiments, these approaches fail to migrate 6 of 21 BIRD databases outright, silently drop up to 25.9% of rows on others, and yield schemas whose ground-truth queries run over an order of magnitude slower as the data scales. We instead propose a conversion pipeline, driven by coding agents with human-in-the-loop verification, that designs each document schema from expected access patterns and rewrites queries to be MongoDB-native. Applying it to BIRD, we build an access-pattern-based text-to-MQL benchmark (AptMQL-Bench). It includes 21 document-oriented databases, 3,186 natural-language requests, and their associated MQL queries—whose databases are migrated from SQLite without data loss and scale efficiently. The strongest model, Claude Opus 4.5, achieves only 57.38% accuracy without external knowledge evidence and 70.34% with it. This indicates that realistic text-to-MQL generation remains challenging.

1 Introduction

Text-to-MQL is the task that converts human-readable text requests into structured MQL queries (MongoDB Query Language). A natural way to build a text-to-MQL benchmark is to convert an existing text-to-SQL benchmark into a document-database benchmark, while reusing its databases, natural-language questions, and SQL queries. Existing conversions are largely mechanical: DocSpider (Özer et al., 2025) maps each relational table to a separate collection one-to-one, while TEND-v2 (Lu et al., 2025) and its multilingual extension MultiTEND (Qin et al., 2025) embed tables along foreign keys. In both cases, the MongoDB schema is derived from relational structure, and MQL is generated from gold SQL under result-equivalence supervision. 1^{1}

However, both mechanical conversion strategies have several limitations. Foreign-key embedding is especially fragile. First, deriving document schemas from foreign-key topology alone can produce poor or even infeasible designs: high-cardinality relationships (e.g. circular reference) are difficult to embed cleanly, and some databases cannot be converted at all (Lu et al., 2025). In our experiments, 6 of the 21 BIRD databases (Li et al., 2023) failed to migrate outright (Table 3): three because a self-referential foreign key triggered infinite recursion, and three produced individual documents so large that they did not fit in MongoDB's 16 MB document limit. Second, the conversion can silently lose data by dropping rows whose foreign keys reference no surviving parent, with row loss reaching 25.9% in the worst case (Table 3). Third, both conversions are inefficient: one-to-one conversion joins tables with unindexed cross-collection $lookups, while foreign-key em-

1^{1}The TEND benchmark exists as two substantially different versions of the same preprint (arXiv:2502.11201). TEND-v2 (version 2) builds MongoDB databases by foreign-key embedding; this is the approach its multilingual extension MultiTEND (Qin et al., 2025) adopts. TEND-v3 (version 3) is a later revision that replaces this with a manually authored, MongoDB-native benchmark. Until now, both TEND versions remain preprints; MultiTEND, which builds on the TEND-v2, is peer-reviewed (ACL Findings 2025). We therefore compare against the foreign-key conversions for TEND-v2 and MultiTEND and report the differences to TEND-v3.

∗^{*}Corresponding author. Work done during internship at MongoDB.

Text-to-SQL BIRD

Agent-based Conversion Pipeline

Text-to-MQL AptMQL-Bench

Figure

Human Review

MQL (Aggregation pipeline)

Figure 1: Conversion pipeline from Text-to-SQL (left) to Text-to-MQL (right).

bedding makes queries $unwind entire nested arrays. These methods result in computationally inefficient MQL queries, with inefficiencies that worsen as data scales, as shown in section 7.

We propose a conversion pipeline that treats schema design as a first-class step and then revises the schema during the migration of the database, as shown in Figure 1. The pipeline is driven by coding agents (e.g. Claude Code 2^{2}) and uses human-in-the-loop verification at each validation stage to prevent hallucinations and data loss. We instantiate our pipeline on MongoDB, a widely used document database, and its query language MQL, with the following stages. First, it designs document schemas from expected access patterns. Second, it migrates the databases and checks that no data is lost. Third, it translates SQL queries into MQL and then optimises the MQL to remove SQL-shaped artefacts. We apply this pipeline to BIRD to build AptMQL-Bench, a benchmark comprising 21 document-oriented databases, 3,186 natural-language requests, and their associated MQL queries. Its databases are migrated without data loss, and its ground-truth MQL queries remain efficient even as the databases grow large.

We also evaluate proprietary and open-source LLMs. The strongest proprietary model, Claude Opus 4.5, achieves 70.34% soft execution accuracy, while its open-source counterpart, GPT-OSS-120B, reaches only 62.46%. These results show that text-to-MQL generation remains challenging. We release the benchmark, prompts, and evaluation scripts to support future work.

References (34)