MongoDB query builder does not convert string IDs to ObjectId in .match() filters
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 74/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- mongodb, typescript
Research direction
Start by tracing how .match() builds and executes filters in the MongoDB query builder, then compare its handling of string IDs with the ORM filter path described in the issue. Use the reported transaction fixture or an equivalent test to check a hexadecimal string against an ObjectId field. Done when the query builder returns the matching document for the string filter, with regression coverage.
Written by the indexing model from the issue text.
Description
Package and version
- Originally reported with
@prisma/[email protected]and[email protected]. - Reproduced against the local
8.0.0-rc.18workspace, based on commite18525ac2840668c77d2d0a8f27f5a282afc30b9. This verification did not use a fresh published-package installation.
What happened?
The MongoDB query builder returns no documents when filtering an ObjectId field with a valid hexadecimal string. The equivalent ORM filter finds the document.
Runtime verification confirmed that ORM string filters and query-builder filters using an explicit ObjectId work. Only the query-builder string filter returned no results.
What did you expect to happen?
A valid hexadecimal string accepted by the ORM's ObjectId filter also matches the corresponding document through the query builder, instead of silently returning no results.
Minimal reproduction
// use prisma-8
// contract.prisma — emit this contract and initialize the MongoDB database.
// An equivalent repository fixture was runtime-tested; this reduced example was not separately run.
model Transaction {
id ObjectId @id @default(auto()) @map("_id")
accountId ObjectId
@@map("transactions")
}
// In mongosh, seed the application's database with one matching document.
db.transactions.insertOne({
_id: ObjectId("507f1f77bcf86cd799439012"),
accountId: ObjectId("507f1f77bcf86cd799439011")
});
// Using the application's existing db instance:
const runtime = await db.runtime();
const accountId = '507f1f77bcf86cd799439011';
const ormRows = await db.orm.transactions.where({ accountId }).all(); // Finds the document.
const plan = db.query
.from('transactions')
.match((f) => f.accountId.eq(accountId))
.build();
const rows = await runtime.query(plan); // Returns []; expected: the matching document.
Environment
Runtime verification:
- Node.js:
26.4.0 - Database: MongoDB
8.2.6, temporary instance managed bymongodb-memory-server - Prisma: local
8.0.0-rc.18workspace
Original report:
- Node.js:
24.9.0 - OS: macOS, Darwin
24.6.0 - Package manager: npm
11.6.0 - Database: MongoDB
8.2.0-rc4, local single-node replica set - Scaffold:
[email protected]
Additional context
Workarounds: use ORM .where({ accountId }), or pass new ObjectId(accountId) to the query-builder comparison.
- Dominant language
- TypeScript
- Stars
- 47.8k
- Forks
- 2.6k
- Avg merge
- 1d 21h
- Merged PRs (30d)
- 227
Getting set up
- Ships a Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from prisma/orm
-
bug/1-unconfirmed kind/bug
Difficulty 1/5 Under an hour Newbie friendliness 90/100
Maintainers usually reply within 1 day
-
get-platform: distros with ID_LIKE=alpine are not detected as musl, so glibc engines are used on Alpine-based imagesPossibly taken A pull request linked to this issue is open or already merged. Open
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
prisma/orm#31281 · 1 comment ·
Maintainers usually reply within 1 day
-
adapter-pg: connectToShadowDb connects to the main database when built from a connection stringMay be free again @cestercian claimed this 10 days ago, and no pull request is open. Open
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
prisma/orm#31196 · 1 comment ·
Maintainers usually reply within 1 day
-
[Prisma 8] Type-check time grows exponentially with chained .include() callsPossibly taken @SiKreuz claimed this 13 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
prisma/orm#31161 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
prisma/orm#31125 · 4 comments · 6 reactions ·
Maintainers usually reply within 1 day
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
tenstorrent/ttnn-visualizer#2526 ·
Maintainers usually reply within 1 day
-
trySessionCache calls /get-session twice when minting session_data (cache miss or expired cookie)Open
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
neondatabase/neon-js#301 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 2 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
tashfeenahmed/freellmapi#2305 ·
Maintainers usually reply within 1 day