@mastra/mongodb 1.18.1 → 1.18.2-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,16 @@
1
1
  # @mastra/mongodb
2
2
 
3
+ ## 1.18.2-alpha.0
4
+
5
+ ### Patch Changes
6
+
7
+ - Experiment results now include isolated metadata snapshots from the dataset items that ran. ([#22005](https://github.com/mastra-ai/mastra/pull/22005))
8
+
9
+ - Enforce atomic conditional background task state updates so cancellation cannot be overwritten during dispatch. Background task storage is no longer exposed by Cloudflare KV or ClickHouse, which cannot provide the required compare-and-set semantics. ([#22228](https://github.com/mastra-ai/mastra/pull/22228))
10
+
11
+ - Updated dependencies [[`aa3a85d`](https://github.com/mastra-ai/mastra/commit/aa3a85daf094c683bb97efdf4b6a696d2e474af5), [`d29d06f`](https://github.com/mastra-ai/mastra/commit/d29d06fe00bbd35b4571150ea04c59d2ed783c71), [`e6516df`](https://github.com/mastra-ai/mastra/commit/e6516dfcdae4f4ac0e7971d84359a81385ee602f), [`0b2a3d1`](https://github.com/mastra-ai/mastra/commit/0b2a3d1783875c5b97b7b36ab3d03d7360e0dde7), [`6bb5d71`](https://github.com/mastra-ai/mastra/commit/6bb5d7193fe9166b219f0fccae17db7a5ae86e65), [`57de7d6`](https://github.com/mastra-ai/mastra/commit/57de7d644ba7146edb4e9e6111ec4fa98c3a59e9), [`e8e299c`](https://github.com/mastra-ai/mastra/commit/e8e299cc6abdfc39947e2fec25803493015d3882), [`edfc548`](https://github.com/mastra-ai/mastra/commit/edfc548886bc7bae17b681f8b6b41a47eb32bcd2), [`a8a4871`](https://github.com/mastra-ai/mastra/commit/a8a4871215f51da95c47129602157ce5372f634a), [`5165cdc`](https://github.com/mastra-ai/mastra/commit/5165cdcdcf50e144bb8113278535196cc9b07065), [`6bb5d71`](https://github.com/mastra-ai/mastra/commit/6bb5d7193fe9166b219f0fccae17db7a5ae86e65), [`9ee8120`](https://github.com/mastra-ai/mastra/commit/9ee8120ce17f76b9f617489e05a283353742690a), [`d975e92`](https://github.com/mastra-ai/mastra/commit/d975e924d4936f46c386bd3dee39c671720289f6), [`1cfa878`](https://github.com/mastra-ai/mastra/commit/1cfa8784d8da0dfaa0317e5048bc48b6084a5ea5), [`c118318`](https://github.com/mastra-ai/mastra/commit/c1183181c9804303db4b511c2e2648f8b714712b), [`fc07c64`](https://github.com/mastra-ai/mastra/commit/fc07c6465043e08e99193a6751a01c56ffc2e7a1), [`542dee2`](https://github.com/mastra-ai/mastra/commit/542dee254167f974ff8cbbbfc0ce10f9a2616a7b), [`a58483c`](https://github.com/mastra-ai/mastra/commit/a58483cff1a9d41fce7c931843f48cb0ac450f64), [`a58483c`](https://github.com/mastra-ai/mastra/commit/a58483cff1a9d41fce7c931843f48cb0ac450f64), [`895e9df`](https://github.com/mastra-ai/mastra/commit/895e9dfc17d6f34299eca64e317ded9e5f5e5ef8)]:
12
+ - @mastra/core@1.62.0-alpha.8
13
+
3
14
  ## 1.18.1
4
15
 
5
16
  ### Patch Changes
@@ -3,7 +3,7 @@ name: mastra-mongodb
3
3
  description: Documentation for @mastra/mongodb. Use when working with @mastra/mongodb APIs, configuration, or implementation.
4
4
  metadata:
5
5
  package: "@mastra/mongodb"
6
- version: "1.18.1"
6
+ version: "1.18.2-alpha.0"
7
7
  ---
8
8
 
9
9
  ## When to use
@@ -29,7 +29,7 @@ Read the individual reference documents for detailed explanations and code examp
29
29
  - [Retrieval, semantic search, reranking](references/reference-rag-retrieval.md) - Guide on retrieval processes in Mastra's RAG systems, including semantic search, filtering, and re-ranking.
30
30
  - [Storing embeddings in a vector database](references/reference-rag-vector-databases.md) - Guide on vector storage options in Mastra, including embedded and dedicated vector databases for similarity search.
31
31
  - [Reference: Composite storage](references/reference-storage-composite.md) - Documentation for combining multiple storage backends in Mastra.
32
- - [Reference: MongoDB vector store](references/reference-vectors-mongodb.md) - Documentation for the MongoDBVector class in Mastra, which provides vector search using MongoDB Atlas and Atlas Vector Search.
32
+ - [Reference: MongoDB vector store](references/reference-vectors-mongodb.md) - Documentation for the MongoDBVector class in Mastra, which provides vector search using MongoDB Atlas and Vector Search.
33
33
 
34
34
 
35
35
  Read [assets/SOURCE_MAP.json](assets/SOURCE_MAP.json) for source code references.
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.18.1",
2
+ "version": "1.18.2-alpha.0",
3
3
  "package": "@mastra/mongodb",
4
4
  "exports": {},
5
5
  "modules": {}
@@ -197,6 +197,7 @@ Each provider page includes installation instructions, configuration parameters,
197
197
  - [Convex](https://mastra.ai/integrations/databases/convex)
198
198
  - [DuckDB](https://mastra.ai/integrations/databases/duckdb)
199
199
  - [DynamoDB](https://mastra.ai/integrations/databases/dynamodb)
200
+ - [Elasticsearch](https://mastra.ai/integrations/databases/elasticsearch)
200
201
  - [Google Cloud Spanner](https://mastra.ai/integrations/databases/spanner)
201
202
  - [LanceDB](https://mastra.ai/integrations/databases/lancedb)
202
203
  - [libSQL](https://mastra.ai/integrations/databases/libsql)
@@ -207,6 +208,7 @@ Each provider page includes installation instructions, configuration parameters,
207
208
  - [OracleDB](https://mastra.ai/integrations/databases/oracledb)
208
209
  - [PostgreSQL](https://mastra.ai/integrations/databases/postgresql)
209
210
  - [Redis](https://mastra.ai/integrations/databases/redis)
211
+ - [Valkey](https://mastra.ai/integrations/databases/valkey)
210
212
  - [Upstash](https://mastra.ai/integrations/databases/upstash)
211
213
 
212
214
  ## Next steps
@@ -32,7 +32,7 @@ bun add @mastra/mongodb@latest
32
32
 
33
33
  ## Usage
34
34
 
35
- Ensure you have a [MongoDB Atlas Local (via Docker)](https://www.mongodb.com/docs/atlas/cli/current/atlas-cli-deploy-docker/) or [MongoDB Atlas Cloud](https://www.mongodb.com/docs/atlas/cli/current/atlas-cli-getting-started/) instance with Atlas Search enabled. MongoDB 7.0+ is recommended.
35
+ Ensure you have a [MongoDB Atlas Local (via Docker)](https://www.mongodb.com/docs/atlas/cli/current/atlas-cli-deploy-docker/) or [MongoDB Atlas Cloud](https://www.mongodb.com/docs/atlas/cli/current/atlas-cli-getting-started/) instance with MongoDB Search enabled. MongoDB 7.0+ is recommended.
36
36
 
37
37
  ```typescript
38
38
  import { MongoDBStore } from '@mastra/mongodb'
@@ -27,9 +27,9 @@ await store.upsert({
27
27
  })
28
28
  ```
29
29
 
30
- ### Using MongoDB Atlas Vector Search
30
+ ### Using MongoDB Vector Search
31
31
 
32
- For detailed setup instructions and best practices, see the [official MongoDB Atlas Vector Search documentation](https://www.mongodb.com/docs/atlas/atlas-vector-search/vector-search-overview/?utm_campaign=devrel\&utm_source=third-party-content\&utm_medium=cta\&utm_content=mastra-docs).
32
+ MongoDB Vector Search is a good solution for teams who want to consolidate vector search, full-text search, and operational data in a single database to minimize infrastructure complexity and maintain production-grade performance. For detailed setup instructions and best practices, see the [official MongoDB Vector Search documentation](https://www.mongodb.com/docs/atlas/atlas-vector-search/vector-search-overview/?utm_campaign=devrel\&utm_source=third-party-content\&utm_medium=cta\&utm_content=mastra-docs).
33
33
 
34
34
  ### Using VoyageAI with MongoDB
35
35
 
@@ -37,7 +37,7 @@ MongoDB works seamlessly with VoyageAI's embedding models, which are optimized f
37
37
 
38
38
  ### Hybrid Search (Vector + Full-Text)
39
39
 
40
- MongoDB supports hybrid search that fuses vector similarity with BM25 full-text search using server-side `$rankFusion` (requires MongoDB >= 8.0; generally available from 8.1, and enabled on Atlas 8.0.x). This is useful when you want to combine semantic and keyword-based retrieval:
40
+ MongoDB supports hybrid search that fuses vector similarity with BM25 full-text search using server-side `$rankFusion` (requires MongoDB >= 8.0; generally available from 8.1, and enabled on MongoDB Atlas 8.0.x). This is useful when you want to combine semantic and keyword-based retrieval:
41
41
 
42
42
  ```ts
43
43
  await store.createSearchIndex({ indexName: 'myCollection', fields: ['text'] })
@@ -420,7 +420,7 @@ Each vector database enforces specific naming conventions for indexes and collec
420
420
 
421
421
  **MongoDB**:
422
422
 
423
- Collection (index) names must:
423
+ Collection and index names must:
424
424
 
425
425
  - Start with a letter or underscore
426
426
  - Be up to 120 bytes long
@@ -2,7 +2,7 @@
2
2
 
3
3
  # MongoDB vector store
4
4
 
5
- The `MongoDBVector` class provides vector search using [MongoDB Atlas Vector Search](https://www.mongodb.com/docs/atlas/atlas-vector-search/). It enables efficient similarity search and metadata filtering within your MongoDB collections.
5
+ The `MongoDBVector` class provides vector search using [MongoDB Vector Search](https://www.mongodb.com/docs/atlas/atlas-vector-search/). It enables efficient similarity search and metadata filtering within your MongoDB collections.
6
6
 
7
7
  ## Installation
8
8
 
@@ -89,11 +89,11 @@ Creates a new vector index (collection) in MongoDB.
89
89
 
90
90
  **metric** (`'cosine' | 'euclidean' | 'dotproduct'`): Distance metric for similarity search (Default: `cosine`)
91
91
 
92
- **filterFields** (`string[]`): Metadata field names to declare as filter fields in the Atlas vectorSearch index (registered as metadata.\<field>). Queries that filter only on declared fields are pushed directly into $vectorSearch instead of pre-filtering candidate \_ids, avoiding the 16 MB BSON limit on large result sets. Filters that reference an undeclared field, or use an operator $vectorSearch does not support, fall back to the pre-filter automatically.
92
+ **filterFields** (`string[]`): Metadata field names to declare as filter fields in the MongoDB vectorSearch index (registered as metadata.\<field>). Queries that filter only on declared fields are pushed directly into $vectorSearch instead of pre-filtering candidate \_ids, avoiding the 16 MB BSON limit on large result sets. Filters that reference an undeclared field, or use an operator $vectorSearch does not support, fall back to the pre-filter automatically.
93
93
 
94
94
  **collectionName** (`string`): Store the vectors on an existing (operational) collection instead of a managed collection named after the index. The collection is never created or dropped by this store when set. Defaults to indexName.
95
95
 
96
- **searchIndexName** (`string`): Name for the Atlas vectorSearch index created on the collection. Defaults to ${indexName}\_vector\_index.
96
+ **searchIndexName** (`string`): Name for the MongoDB vectorSearch index created on the collection. Defaults to ${indexName}\_vector\_index.
97
97
 
98
98
  **allowWrites** (`boolean`): Opt-in to write operations (upsert, updateVector, deleteVector, deleteVectors) on a bring-your-own collection. By default a BYO index is read-only: the store never modifies or deletes caller-owned operational documents. Ignored for managed collections, which are always writable. The policy is persisted with the index registration and survives restarts. (Default: `false`)
99
99
 
@@ -143,7 +143,7 @@ Searches for similar vectors with optional metadata filtering.
143
143
 
144
144
  ### `createSearchIndex()`
145
145
 
146
- Provisions an Atlas Search (BM25/full-text) index on the collection backing an index and records it as the text-search index that `textQuery()` and `hybridQuery()` will target.
146
+ Provisions a MongoDB Search (BM25/full-text) index on the collection backing an index and records it as the text-search index that `textQuery()` and `hybridQuery()` will target.
147
147
 
148
148
  **Managed vs. bring-your-own collections:**
149
149
 
@@ -159,7 +159,7 @@ Naming:
159
159
 
160
160
  **fields** (`string[]`): Field names to index for full-text search. Omit for dynamic mapping (all string fields).
161
161
 
162
- **searchIndexName** (`string`): Name for the Atlas Search index. When fields is provided and this is omitted, a distinct default name that is unique per logical index is used, so the field mapping is not shadowed by the auto-created dynamic index and two logical indexes on the same collection do not collide. (Default: ``${collectionName}_search_index (or ${collectionName}_${indexName}_search_fields_index when `fields` is given)``)
162
+ **searchIndexName** (`string`): Name for the MongoDB Search index. When fields is provided and this is omitted, a distinct default name that is unique per logical index is used, so the field mapping is not shadowed by the auto-created dynamic index and two logical indexes on the same collection do not collide. (Default: ``${collectionName}_search_index (or ${collectionName}_${indexName}_search_fields_index when `fields` is given)``)
163
163
 
164
164
  **waitUntilReady** (`boolean`): When true, block until the provisioned full-text index reports READY before resolving. Defaults to false to avoid surprising latency; call waitForSearchIndexReady() explicitly if you prefer to await separately. (Default: `false`)
165
165
 
@@ -174,7 +174,7 @@ The field-mapped index name includes the logical `indexName`, so two logical ind
174
174
 
175
175
  ### `waitForSearchIndexReady()`
176
176
 
177
- Waits for the full-text (BM25) search index of an index to become READY. `waitForIndexReady()` polls only the vectorSearch index; `createSearchIndex()` returns while the Atlas Search full-text index is still building, so an immediate `textQuery()`/`hybridQuery()` can intermittently fail. Call this (or pass `waitUntilReady: true` to `createSearchIndex()`) to block until the resolved text index reports READY.
177
+ Waits for the full-text (BM25) search index of an index to become READY. `waitForIndexReady()` polls only the vectorSearch index; `createSearchIndex()` returns while the MongoDB Search full-text index is still building, so an immediate `textQuery()`/`hybridQuery()` can intermittently fail. Call this (or pass `waitUntilReady: true` to `createSearchIndex()`) to block until the resolved text index reports READY.
178
178
 
179
179
  **indexName** (`string`): Logical name of the index whose text index to wait for
180
180
 
@@ -191,7 +191,7 @@ await store.waitForSearchIndexReady({ indexName: 'precedents' })
191
191
 
192
192
  ### `textQuery()`
193
193
 
194
- Runs a full-text (BM25) search against an Atlas Search index. By default it targets the text-search index recorded for this index (set by `createSearchIndex()`, or the dynamic `${collectionName}_search_index` auto-created by `createIndex()`). Pass `searchIndexName` to target a specific index for this call.
194
+ Runs a full-text (BM25) search against a MongoDB Search index. By default it targets the text-search index recorded for this index (set by `createSearchIndex()`, or the dynamic `${collectionName}_search_index` auto-created by `createIndex()`). Pass `searchIndexName` to target a specific index for this call.
195
195
 
196
196
  Metadata filters here (like `hybridQuery()`) are applied via a `$match` stage. For the vector branch of `hybridQuery()`, filters on fields not declared via `filterFields` at index creation are transparently materialised as candidate `_id`s (the same fallback `query()` uses), so undeclared-field filters don't error.
197
197
 
@@ -220,7 +220,7 @@ const results = await store.textQuery({
220
220
 
221
221
  ### `hybridQuery()`
222
222
 
223
- Runs a hybrid search that fuses vector similarity and full-text results using MongoDB's server-side `$rankFusion`. It requires MongoDB >= 8.0 and is generally available from 8.1. On 8.0.x, it may require a MongoDB support case for enablement. It runs where enabled, including Atlas 8.0.x. A full-text search index must exist: it's auto-created for managed indexes, but for a bring-your-own collection you must call `createSearchIndex()` first (opt-in).
223
+ Runs a hybrid search that fuses vector similarity and full-text results using MongoDB's server-side `$rankFusion`. It requires MongoDB >= 8.0 and is generally available from 8.1. On 8.0.x, it may require a MongoDB support case for enablement. It runs where enabled, including MongoDB Atlas 8.0.x. A full-text search index must exist: it's auto-created for managed indexes, but for a bring-your-own collection you must call `createSearchIndex()` first (opt-in).
224
224
 
225
225
  **indexName** (`string`): Name of the Mastra index to search
226
226
 
@@ -253,7 +253,7 @@ const results = await store.hybridQuery({
253
253
  })
254
254
  ```
255
255
 
256
- `hybridQuery()` requires MongoDB >= 8.0 for the `$rankFusion` stage. The stage is generally available from 8.1. On 8.0.x, it may need a MongoDB support case to enable and runs where enabled, such as Atlas 8.0.x. If you're running an older version, or `$rankFusion` isn't enabled on your 8.0.x deployment, use `query()` and `textQuery()` separately and merge the results client-side.
256
+ `hybridQuery()` requires MongoDB >= 8.0 for the `$rankFusion` stage. The stage is generally available from 8.1. On 8.0.x, it may need a MongoDB support case to enable and runs where enabled, such as MongoDB Atlas 8.0.x. If you're running an older version, or `$rankFusion` isn't enabled on your 8.0.x deployment, use `query()` and `textQuery()` separately and merge the results client-side.
257
257
 
258
258
  ### `describeIndex()`
259
259
 
@@ -276,7 +276,7 @@ interface IndexStats {
276
276
  Deletes a vector index. Behavior depends on how the index was created:
277
277
 
278
278
  - **Managed index** (created without `collectionName`): drops the entire collection and all its data.
279
- - **Bring-your-own index** (created with `collectionName`): drops the Atlas vectorSearch index. If `createSearchIndex()` provisioned a companion full-text search index, it drops that index too. The caller's operational collection and its documents are preserved. This store never drops a collection it didn't create.
279
+ - **Bring-your-own index** (created with `collectionName`): drops the MongoDB vectorSearch index. If `createSearchIndex()` provisioned a companion full-text search index, it drops that index too. The caller's operational collection and its documents are preserved. This store never drops a collection it didn't create.
280
280
 
281
281
  The BYO classification is recorded durably when the index is created, so it's applied correctly even by a different process (e.g. an index created by a setup job and later deleted by a long-lived service). Always pass the **logical index name** (the `indexName` used at `createIndex`), not the physical collection name.
282
282
 
@@ -429,7 +429,7 @@ await store.createSearchIndex({ indexName: 'precedents', fields: ['note'] })
429
429
 
430
430
  Embeddings are numeric vectors used by memory's `semanticRecall` to retrieve related messages by meaning (not keywords).
431
431
 
432
- > **Note:** MongoDB Atlas Vector Search is recommended for production use. For self-hosted deployments, Vector Search is available with [local Atlas deployments via the Atlas CLI](https://www.mongodb.com/docs/atlas/cli/current/atlas-cli-deploy-local/).
432
+ > **Note:** MongoDB Vector Search is recommended for production use. For self-hosted deployments, Vector Search is available with [local Atlas deployments via the Atlas CLI](https://www.mongodb.com/docs/atlas/cli/current/atlas-cli-deploy-local/).
433
433
 
434
434
  This setup uses FastEmbed, a local embedding model, to generate vector embeddings. To use this, install `@mastra/fastembed`:
435
435
 
package/dist/index.cjs CHANGED
@@ -10,7 +10,7 @@ let _mastra_core_agent = require("@mastra/core/agent");
10
10
  let _mastra_core_evals = require("@mastra/core/evals");
11
11
  let _mastra_core_storage_domains_skills = require("@mastra/core/storage/domains/skills");
12
12
  //#region package.json
13
- var version = "1.18.1";
13
+ var version = "1.18.2-alpha.0";
14
14
  //#endregion
15
15
  //#region src/vector/filter.ts
16
16
  /**
@@ -2335,7 +2335,7 @@ var BackgroundTasksStorageMongoDB = class BackgroundTasksStorageMongoDB extends
2335
2335
  async createTask(task) {
2336
2336
  await (await this.getCollection()).insertOne(toDoc(task));
2337
2337
  }
2338
- async updateTask(taskId, update) {
2338
+ async updateTask(taskId, update, options) {
2339
2339
  const $set = {};
2340
2340
  if ("status" in update) $set.status = update.status;
2341
2341
  if ("result" in update) $set.result = update.result ?? null;
@@ -2345,8 +2345,11 @@ var BackgroundTasksStorageMongoDB = class BackgroundTasksStorageMongoDB extends
2345
2345
  if ("startedAt" in update) $set.startedAt = update.startedAt?.toISOString() ?? null;
2346
2346
  if ("suspendedAt" in update) $set.suspendedAt = update.suspendedAt?.toISOString() ?? null;
2347
2347
  if ("completedAt" in update) $set.completedAt = update.completedAt?.toISOString() ?? null;
2348
- if (Object.keys($set).length === 0) return;
2349
- await (await this.getCollection()).updateOne({ id: taskId }, { $set });
2348
+ if (Object.keys($set).length === 0) return false;
2349
+ return (await (await this.getCollection()).updateOne({
2350
+ id: taskId,
2351
+ ...options?.expectedStatus ? { status: options.expectedStatus } : {}
2352
+ }, { $set })).matchedCount > 0;
2350
2353
  }
2351
2354
  async getTask(taskId) {
2352
2355
  const doc = await (await this.getCollection()).findOne({ id: taskId });
@@ -3704,6 +3707,7 @@ function transformExperimentResultRow(row) {
3704
3707
  input: parseJsonField(row.input),
3705
3708
  output: parseJsonField(row.output) ?? null,
3706
3709
  groundTruth: parseJsonField(row.groundTruth) ?? null,
3710
+ metadata: parseJsonField(row.metadata) ?? null,
3707
3711
  error: parseJsonField(row.error) ?? null,
3708
3712
  startedAt: toDate(row.startedAt),
3709
3713
  completedAt: toDate(row.completedAt),
@@ -4087,6 +4091,7 @@ var MongoDBExperimentsStorage = class MongoDBExperimentsStorage extends _mastra_
4087
4091
  input: input.input,
4088
4092
  output: input.output ?? null,
4089
4093
  groundTruth: input.groundTruth ?? null,
4094
+ metadata: input.metadata ?? null,
4090
4095
  error: input.error ?? null,
4091
4096
  startedAt: input.startedAt,
4092
4097
  completedAt: input.completedAt,
@@ -4110,6 +4115,7 @@ var MongoDBExperimentsStorage = class MongoDBExperimentsStorage extends _mastra_
4110
4115
  input: input.input,
4111
4116
  output: input.output ?? null,
4112
4117
  groundTruth: input.groundTruth ?? null,
4118
+ metadata: input.metadata ?? null,
4113
4119
  error: input.error ?? null,
4114
4120
  startedAt: input.startedAt,
4115
4121
  completedAt: input.completedAt,
@@ -4145,6 +4151,7 @@ var MongoDBExperimentsStorage = class MongoDBExperimentsStorage extends _mastra_
4145
4151
  input: input.input,
4146
4152
  output: input.output ?? null,
4147
4153
  groundTruth: input.groundTruth ?? null,
4154
+ metadata: input.metadata ?? null,
4148
4155
  error: input.error ?? null,
4149
4156
  startedAt: input.startedAt,
4150
4157
  completedAt: input.completedAt,