Package and version
@prisma-next/mongo-adapter / @prisma-next/mongo-query-builder @ 0.14.0 (repo main @ 284a838)
What happened?
A pipeline builder match() with an equality filter on _id never matches any document — it silently returns zero rows for both value forms:
- passing the hex string (
f._id.eq('665f0c…')) — this typechecks cleanly, making it a silent zero-rows trap;
- passing a bson
ObjectId instance.
The cause is in resolveValue() (packages/3-mongo-target/2-mongo-adapter/src/resolve-value.ts): after the MongoParamRef / null / Date / Array checks, any other object falls into the generic-object branch, which walks it with Object.entries() and rebuilds it as a plain object. A bson ObjectId therefore gets destructured into its internal buffer property and reaches the wire as a plain { buffer: … }-shaped document instead of an ObjectId, so the equality comparison against the stored ObjectId is never true. The hex-string form likewise never becomes an ObjectId on the encode path.
What did you expect to happen?
An _id equality filter matches the stored document: hex strings are encoded to ObjectId via the mongo/objectid@1 codec, and ObjectId instances pass through to the driver untouched (i.e. resolveValue needs a BSON-type guard alongside the existing Date guard).
Minimal reproduction
const inserted = await run(query.from('orders').insertOne({ status: 'active' }));
const id = inserted.insertedId; // hex string per the read surface
const rows = await run(
query
.from('orders')
.match((f) => f._id.eq(id)) // typechecks; also fails with new ObjectId(id)
.build(),
);
// rows === [] — expected the inserted document
Reproduced against mongodb-memory-server with a failing spec (specs/pipeline-builder.mongo.spec.ts in a local docs-validation harness); both the hex-string and ObjectId variants return [].
Environment
- Node: 24.x
- OS: macOS 15 (Darwin 24.6.0)
- Package manager: pnpm
- Database: MongoDB via mongodb-memory-server
Additional context
Related but distinct from #577, which is about the decode side (create() returning raw ObjectId instead of the hex string). This issue is the encode side: filter values are never turned into ObjectIds, so _id equality is unusable from the pipeline builder. Found while validating the examples in docs/reference/Mongo Pipeline Builder.md against the runtime.
Package and version
@prisma-next/mongo-adapter/@prisma-next/mongo-query-builder@ 0.14.0 (repomain@ 284a838)What happened?
A pipeline builder
match()with an equality filter on_idnever matches any document — it silently returns zero rows for both value forms:f._id.eq('665f0c…')) — this typechecks cleanly, making it a silent zero-rows trap;ObjectIdinstance.The cause is in
resolveValue()(packages/3-mongo-target/2-mongo-adapter/src/resolve-value.ts): after theMongoParamRef/null/Date/Arraychecks, any other object falls into the generic-object branch, which walks it withObject.entries()and rebuilds it as a plain object. A bsonObjectIdtherefore gets destructured into its internalbufferproperty and reaches the wire as a plain{ buffer: … }-shaped document instead of anObjectId, so the equality comparison against the storedObjectIdis never true. The hex-string form likewise never becomes anObjectIdon the encode path.What did you expect to happen?
An
_idequality filter matches the stored document: hex strings are encoded toObjectIdvia themongo/objectid@1codec, andObjectIdinstances pass through to the driver untouched (i.e.resolveValueneeds a BSON-type guard alongside the existingDateguard).Minimal reproduction
Reproduced against mongodb-memory-server with a failing spec (
specs/pipeline-builder.mongo.spec.tsin a local docs-validation harness); both the hex-string andObjectIdvariants return[].Environment
Additional context
Related but distinct from #577, which is about the decode side (
create()returning rawObjectIdinstead of the hex string). This issue is the encode side: filter values are never turned intoObjectIds, so_idequality is unusable from the pipeline builder. Found while validating the examples indocs/reference/Mongo Pipeline Builder.mdagainst the runtime.