-
Type:
Improvement
-
Resolution: Unresolved
-
Priority:
Unknown
-
None
-
Affects Version/s: None
-
Component/s: ABX
-
None
-
None
-
None
-
None
-
None
-
None
TL;DR
Query results turn every document _id into a string. For _id types other than string or ObjectId, that string no longer matches the stored value, so lookups by that id silently find nothing. Fail with a clear error instead.
Context
With a bring-your-own (BYO) collection, query() returns each document's _id as the string id field of the result, using toString(). Mastra matches an id back to a document as a string, and also as an ObjectId when it's a 24-character hex string. Other _id types, such as numbers, don't survive this: _id: 42 becomes '42', which matches nothing.
The docs say ObjectId _id}}s are supported but don't say other types aren't. BYO collections are read-only, and the docs tell users to write embeddings from their application, so the application will often use {{hit.id to find the source document. With the deprecated allowWrites: true, deleteVector() and updateVector() also silently match nothing.
Desired User Experience
// The collection contains { _id: 42, note: '...', embedding: [...] } const [hit] = await store.query({ indexName: 'precedents', queryVector: embedding, topK: 1 }); // Before: hit.id === '42'. db.collection('transactions').findOne({ _id: hit.id }) returns null, // and nothing explains why. // After: the query fails with an error that names the supported _id types (string, ObjectId). // String and ObjectId collections are unaffected.
Task
Goals: Users find out right away when their collection's _id type is incompatible, instead of getting ids that match nothing.
Where: idToString() and buildIdMatch() in stores/mongodb/src/vector/index.ts, and the _id note in the docs. Live page: mastra.ai/integrations/vectors/mongodb#indexing-an-existing-collection.
Acceptance Criteria
- [ ] Results with an unsupported _id type produce an actionable error instead of an unmatchable id.
- [ ] String and ObjectId collections behave as before, without extra collection scans.
- [ ] The "Indexing an existing collection" docs list the supported _id types.