@mastra/mongodb 1.14.0-alpha.0 → 1.15.0-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 +49 -0
- package/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/index.cjs +38 -14
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +39 -15
- package/dist/index.js.map +1 -1
- package/dist/storage/domains/memory/index.d.ts.map +1 -1
- package/package.json +8 -7
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,54 @@
|
|
|
1
1
|
# @mastra/mongodb
|
|
2
2
|
|
|
3
|
+
## 1.15.0-alpha.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- Added exact metadata filtering to message history queries across Memory APIs and supported storage providers. ([#19991](https://github.com/mastra-ai/mastra/pull/19991))
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
const messages = await memory.recall({
|
|
11
|
+
threadId: 'thread-1',
|
|
12
|
+
filter: {
|
|
13
|
+
metadata: {
|
|
14
|
+
status: 'done',
|
|
15
|
+
priority: 'high',
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
});
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Multiple fields use AND semantics. Supported values are strings, finite numbers, booleans, and `null`.
|
|
22
|
+
|
|
23
|
+
### Patch Changes
|
|
24
|
+
|
|
25
|
+
- Updated dependencies [[`0dca9d0`](https://github.com/mastra-ai/mastra/commit/0dca9d0b1356024a53b72ea6f040db528b126caa)]:
|
|
26
|
+
- @mastra/core@1.54.0-alpha.0
|
|
27
|
+
|
|
28
|
+
## 1.14.0
|
|
29
|
+
|
|
30
|
+
### Minor Changes
|
|
31
|
+
|
|
32
|
+
- Added a `filterFields` option to `MongoDBVector.createIndex()`. Declaring the metadata fields you filter on lets Mastra register them as native filter fields in the Atlas vectorSearch index, so filtered queries are pushed straight into `$vectorSearch` instead of first materialising matching document `_id`s. This removes the 16 MB BSON ceiling that previously capped metadata-filtered queries at roughly 342,000 matching documents. ([#19006](https://github.com/mastra-ai/mastra/pull/19006))
|
|
33
|
+
|
|
34
|
+
```ts
|
|
35
|
+
await vectorStore.createIndex({
|
|
36
|
+
indexName: 'my-index',
|
|
37
|
+
dimension: 1536,
|
|
38
|
+
metric: 'cosine',
|
|
39
|
+
filterFields: ['category', 'tenant_id'],
|
|
40
|
+
});
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
Queries that filter only on declared fields (using operators Atlas Vector Search supports) take the fast path automatically. Filters that reference an undeclared field, or use an unsupported operator, keep working through the existing pre-filter.
|
|
44
|
+
|
|
45
|
+
### Patch Changes
|
|
46
|
+
|
|
47
|
+
- Fixed `MongoDBVector.createIndex()` leaving index setup incomplete. Previously, when the vector search index already existed, the call silently skipped creating the companion full-text search index. Repeated or interrupted `createIndex()` calls now finish creating the remaining search index instead of leaving setup incomplete. ([#19006](https://github.com/mastra-ai/mastra/pull/19006))
|
|
48
|
+
|
|
49
|
+
- Updated dependencies [[`ec857fc`](https://github.com/mastra-ai/mastra/commit/ec857fc79c264b53b38e16478c789b7177f2ad59), [`d7385ad`](https://github.com/mastra-ai/mastra/commit/d7385ad9e88f9e4f33d15c0ec0bfebedde0cbc2e), [`41a5392`](https://github.com/mastra-ai/mastra/commit/41a5392d9f6c5e18d6b227f0fc0ddf49c50774e9), [`3d6e539`](https://github.com/mastra-ai/mastra/commit/3d6e539272eb2ea0407034605ee1906b3be06b39), [`1426af2`](https://github.com/mastra-ai/mastra/commit/1426af24975879c000d13ac75673f630fcc970c1), [`a40adeb`](https://github.com/mastra-ai/mastra/commit/a40adeb222b961a56a58af56a106106525721b74), [`8a0d145`](https://github.com/mastra-ai/mastra/commit/8a0d145aadbdf7278665aceaaec364b35dd9bd94), [`bd2f1d2`](https://github.com/mastra-ai/mastra/commit/bd2f1d274d05e60e2366f005ea0d94d5cea0d5ff), [`e1f2fae`](https://github.com/mastra-ai/mastra/commit/e1f2faebaf048c3d4c2e2c01d293767c195d5794), [`63aa799`](https://github.com/mastra-ai/mastra/commit/63aa799c6b44eacc7806cda6846b7c5bbee06b37), [`b7e79c3`](https://github.com/mastra-ai/mastra/commit/b7e79c3c02ac5cd415db34ba0975ceafc1464333), [`675fbff`](https://github.com/mastra-ai/mastra/commit/675fbff84d3274391b33e852f76083c38a5514e5), [`da009e1`](https://github.com/mastra-ai/mastra/commit/da009e1aacd89ed94b8d1b2af09c9d4fe7c4db49), [`3b77e77`](https://github.com/mastra-ai/mastra/commit/3b77e7704936522e4769d29de1b5ea6901f302bd), [`c7d30cd`](https://github.com/mastra-ai/mastra/commit/c7d30cd86009c407df91105591f03cd6e3d2854d), [`21a0eb8`](https://github.com/mastra-ai/mastra/commit/21a0eb86746ba0b703acea360d4f84c6a5a493f2), [`8b20926`](https://github.com/mastra-ai/mastra/commit/8b20926cd59e2ba3d66458e062fa0e6e2ada3e68), [`975295d`](https://github.com/mastra-ai/mastra/commit/975295d418552f0d46a59edfef4c3ee555f9930a), [`73db8db`](https://github.com/mastra-ai/mastra/commit/73db8db90d69ab6153c7942749f624db0d96952d), [`6b1bf3b`](https://github.com/mastra-ai/mastra/commit/6b1bf3b9494bd51aa8f654c68c9355d6046fa2a1), [`35c2181`](https://github.com/mastra-ai/mastra/commit/35c2181e6a50e47c90ba36260db7c9723d54696f), [`0a2c22c`](https://github.com/mastra-ai/mastra/commit/0a2c22c902604439ec490319e14c17f331e0c84c), [`4cfdd64`](https://github.com/mastra-ai/mastra/commit/4cfdd645794feaea0c4ea711e70ecdfbef0c5b8e), [`b75d749`](https://github.com/mastra-ai/mastra/commit/b75d749621ff5d17e86bcb4ee809d301fb4f7cf3), [`821648b`](https://github.com/mastra-ai/mastra/commit/821648bf2871ef840100c7bacbecf676010bd12a), [`de86fd7`](https://github.com/mastra-ai/mastra/commit/de86fd7119f0438381d1a642e3d258143c0b9c29), [`2745031`](https://github.com/mastra-ai/mastra/commit/2745031d1d4a4978f037092da371428c32e2842a), [`b4b7ea8`](https://github.com/mastra-ai/mastra/commit/b4b7ea8733f033fc441ea47ed03f6afb17ec2248), [`3a8024c`](https://github.com/mastra-ai/mastra/commit/3a8024ce615f8aa89479c0d71fe61d10bb0040be), [`35865a5`](https://github.com/mastra-ai/mastra/commit/35865a53e194aa9634d6a70a97010e7a6b9d58b1), [`74faf8b`](https://github.com/mastra-ai/mastra/commit/74faf8bd9c1018f2492653c06b1e25fc8300e9e6), [`ef03fbc`](https://github.com/mastra-ai/mastra/commit/ef03fbcc556bcbc04c9b3d06fab88771ecaa043c), [`675fbff`](https://github.com/mastra-ai/mastra/commit/675fbff84d3274391b33e852f76083c38a5514e5), [`70687f7`](https://github.com/mastra-ai/mastra/commit/70687f7e495a322a02070b4a67cb0c77a5ca91ec), [`1fadac4`](https://github.com/mastra-ai/mastra/commit/1fadac44537caeefe81f9f775ae2f2f3d94e9069), [`73db8db`](https://github.com/mastra-ai/mastra/commit/73db8db90d69ab6153c7942749f624db0d96952d), [`76b7181`](https://github.com/mastra-ai/mastra/commit/76b71810366e6d90b9d3973149d1c7ba3659ffb9), [`792ec9a`](https://github.com/mastra-ai/mastra/commit/792ec9a0869bab8274cf5e0ed2840738737a1607), [`712b864`](https://github.com/mastra-ai/mastra/commit/712b864aa1ed12b14c54390ec17b69de163c37f7), [`85e4fb5`](https://github.com/mastra-ai/mastra/commit/85e4fb50087a81c74df3a762f53b56373db0b912), [`0c0e8d7`](https://github.com/mastra-ai/mastra/commit/0c0e8d7becd4d1445c656b78d5d845f606c1ff9d), [`a7bbe77`](https://github.com/mastra-ai/mastra/commit/a7bbe773577f60bc4761b534ef7ec6b476332dad), [`72e437c`](https://github.com/mastra-ai/mastra/commit/72e437c515942c80b9def5b026e0bdee61b469d9), [`8f7a5de`](https://github.com/mastra-ai/mastra/commit/8f7a5dedc246cdc938bb65516703cf9b27b03756), [`a7bbe77`](https://github.com/mastra-ai/mastra/commit/a7bbe773577f60bc4761b534ef7ec6b476332dad), [`11f6cd9`](https://github.com/mastra-ai/mastra/commit/11f6cd96fe42582403416608beb212cc1a2cc79e), [`ef03c0c`](https://github.com/mastra-ai/mastra/commit/ef03c0cfc62367a458e4cc56462e2148b35681c5), [`4fb4d88`](https://github.com/mastra-ai/mastra/commit/4fb4d881bc107acee13890ad4d78661016c510ed), [`4e68363`](https://github.com/mastra-ai/mastra/commit/4e683634f94ebd062d26a3bb6093a8dfc7263d37), [`c328769`](https://github.com/mastra-ai/mastra/commit/c3287698ff8ef98dba86d415faa566fa3e5f4d56), [`9f7c67a`](https://github.com/mastra-ai/mastra/commit/9f7c67abeeb52c41c51a9b5edee60b62afe7cd8d), [`3b65e68`](https://github.com/mastra-ai/mastra/commit/3b65e68d7f1c771c7a70eea42d83fefdd28cad88), [`4eba27a`](https://github.com/mastra-ai/mastra/commit/4eba27adcf60f991df0e62f94b3e75b4e67f3b4b), [`c701be3`](https://github.com/mastra-ai/mastra/commit/c701be32d7d9aa94a66da8c6cc38dcac6856f464), [`db650ce`](https://github.com/mastra-ai/mastra/commit/db650ce490348914e85b93651d83acdf8f2a4c31), [`232fcbc`](https://github.com/mastra-ai/mastra/commit/232fcbc14fce625dd672ba043329c0b732c62be2), [`6354eeb`](https://github.com/mastra-ai/mastra/commit/6354eeb32efa9f5f68f51dda394e90e2ee76f1fb), [`a8799bb`](https://github.com/mastra-ai/mastra/commit/a8799bb8e44f4a60d01e4e2acd3448ff80bf14f8), [`3d6e539`](https://github.com/mastra-ai/mastra/commit/3d6e539272eb2ea0407034605ee1906b3be06b39), [`e3868e2`](https://github.com/mastra-ai/mastra/commit/e3868e22babfffd0133771669ca724501c2dd58e), [`9251370`](https://github.com/mastra-ai/mastra/commit/9251370ad413af464aa22d7566338bec5613e8de), [`3491666`](https://github.com/mastra-ai/mastra/commit/34916663c4fdd43b48c21f4ab2d5fb6dcccc94f9), [`c0bec73`](https://github.com/mastra-ai/mastra/commit/c0bec732c93d1a22ae5e51ed66cf8cacca8bd6a6)]:
|
|
50
|
+
- @mastra/core@1.52.0
|
|
51
|
+
|
|
3
52
|
## 1.14.0-alpha.0
|
|
4
53
|
|
|
5
54
|
### Minor Changes
|
package/dist/docs/SKILL.md
CHANGED
|
@@ -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.
|
|
6
|
+
version: "1.15.0-alpha.0"
|
|
7
7
|
---
|
|
8
8
|
|
|
9
9
|
## When to use
|
package/dist/index.cjs
CHANGED
|
@@ -15,7 +15,7 @@ var skills = require('@mastra/core/storage/domains/skills');
|
|
|
15
15
|
|
|
16
16
|
// package.json
|
|
17
17
|
var package_default = {
|
|
18
|
-
version: "1.
|
|
18
|
+
version: "1.15.0-alpha.0"};
|
|
19
19
|
var MongoDBFilterTranslator = class extends filter.BaseFilterTranslator {
|
|
20
20
|
getSupportedOperators() {
|
|
21
21
|
return {
|
|
@@ -5273,6 +5273,7 @@ var MemoryStorageMongoDB = class _MemoryStorageMongoDB extends storage.MemorySto
|
|
|
5273
5273
|
}
|
|
5274
5274
|
async listMessages(args) {
|
|
5275
5275
|
const { threadId, resourceId, include, filter, perPage: perPageInput, page = 0, orderBy } = args;
|
|
5276
|
+
const metadataFilter = storage.validateStorageMetadataFilter(filter?.metadata);
|
|
5276
5277
|
const threadIds = Array.isArray(threadId) ? threadId : [threadId];
|
|
5277
5278
|
if (threadIds.length === 0 || threadIds.some((id) => !id.trim())) {
|
|
5278
5279
|
throw new error.MastraError(
|
|
@@ -5328,16 +5329,27 @@ var MemoryStorageMongoDB = class _MemoryStorageMongoDB extends storage.MemorySto
|
|
|
5328
5329
|
hasMore: false
|
|
5329
5330
|
};
|
|
5330
5331
|
}
|
|
5331
|
-
const total = await collection.countDocuments(query);
|
|
5332
5332
|
const messages = [];
|
|
5333
|
+
let total = 0;
|
|
5333
5334
|
if (perPage !== 0) {
|
|
5334
5335
|
const sortObj = { [field]: sortOrder };
|
|
5335
|
-
|
|
5336
|
-
|
|
5337
|
-
|
|
5336
|
+
if (metadataFilter) {
|
|
5337
|
+
const candidates = (await collection.find(query).sort(sortObj).toArray()).map((row) => this.parseRow(row)).filter((message) => storage.storageMessageMatchesMetadataFilter(message.content, metadataFilter));
|
|
5338
|
+
total = candidates.length;
|
|
5339
|
+
messages.push(...perPageInput === false ? candidates : candidates.slice(offset, offset + perPage));
|
|
5340
|
+
} else {
|
|
5341
|
+
total = await collection.countDocuments(query);
|
|
5342
|
+
let cursor = collection.find(query).sort(sortObj).skip(offset);
|
|
5343
|
+
if (perPageInput !== false) {
|
|
5344
|
+
cursor = cursor.limit(perPage);
|
|
5345
|
+
}
|
|
5346
|
+
const dataResult = await cursor.toArray();
|
|
5347
|
+
messages.push(...dataResult.map((row) => this.parseRow(row)));
|
|
5338
5348
|
}
|
|
5339
|
-
|
|
5340
|
-
|
|
5349
|
+
} else if (metadataFilter) {
|
|
5350
|
+
total = (await collection.find(query).toArray()).map((row) => this.parseRow(row)).filter((message) => storage.storageMessageMatchesMetadataFilter(message.content, metadataFilter)).length;
|
|
5351
|
+
} else {
|
|
5352
|
+
total = await collection.countDocuments(query);
|
|
5341
5353
|
}
|
|
5342
5354
|
if (total === 0 && messages.length === 0 && (!include || include.length === 0)) {
|
|
5343
5355
|
return {
|
|
@@ -5367,7 +5379,7 @@ var MemoryStorageMongoDB = class _MemoryStorageMongoDB extends storage.MemorySto
|
|
|
5367
5379
|
finalMessages.filter((m) => m.threadId && threadIdSet.has(m.threadId)).map((m) => m.id)
|
|
5368
5380
|
);
|
|
5369
5381
|
const allThreadMessagesReturned = returnedThreadMessageIds.size >= total;
|
|
5370
|
-
const hasMore = perPageInput !== false && !allThreadMessagesReturned && offset + perPage < total;
|
|
5382
|
+
const hasMore = metadataFilter ? perPageInput !== false && offset + perPage < total : perPageInput !== false && !allThreadMessagesReturned && offset + perPage < total;
|
|
5371
5383
|
return {
|
|
5372
5384
|
messages: finalMessages,
|
|
5373
5385
|
total,
|
|
@@ -5401,6 +5413,7 @@ var MemoryStorageMongoDB = class _MemoryStorageMongoDB extends storage.MemorySto
|
|
|
5401
5413
|
}
|
|
5402
5414
|
async listMessagesByResourceId(args) {
|
|
5403
5415
|
const { resourceId, include, filter, perPage: perPageInput, page = 0, orderBy } = args;
|
|
5416
|
+
const metadataFilter = storage.validateStorageMetadataFilter(filter?.metadata);
|
|
5404
5417
|
if (!resourceId || typeof resourceId !== "string" || resourceId.trim().length === 0) {
|
|
5405
5418
|
throw new error.MastraError(
|
|
5406
5419
|
{
|
|
@@ -5456,16 +5469,27 @@ var MemoryStorageMongoDB = class _MemoryStorageMongoDB extends storage.MemorySto
|
|
|
5456
5469
|
hasMore: false
|
|
5457
5470
|
};
|
|
5458
5471
|
}
|
|
5459
|
-
const total = await collection.countDocuments(query);
|
|
5460
5472
|
const messages = [];
|
|
5473
|
+
let total = 0;
|
|
5461
5474
|
if (perPage !== 0) {
|
|
5462
5475
|
const sortObj = { [field]: sortOrder };
|
|
5463
|
-
|
|
5464
|
-
|
|
5465
|
-
|
|
5476
|
+
if (metadataFilter) {
|
|
5477
|
+
const candidates = (await collection.find(query).sort(sortObj).toArray()).map((row) => this.parseRow(row)).filter((message) => storage.storageMessageMatchesMetadataFilter(message.content, metadataFilter));
|
|
5478
|
+
total = candidates.length;
|
|
5479
|
+
messages.push(...perPageInput === false ? candidates : candidates.slice(offset, offset + perPage));
|
|
5480
|
+
} else {
|
|
5481
|
+
total = await collection.countDocuments(query);
|
|
5482
|
+
let cursor = collection.find(query).sort(sortObj).skip(offset);
|
|
5483
|
+
if (perPageInput !== false) {
|
|
5484
|
+
cursor = cursor.limit(perPage);
|
|
5485
|
+
}
|
|
5486
|
+
const dataResult = await cursor.toArray();
|
|
5487
|
+
messages.push(...dataResult.map((row) => this.parseRow(row)));
|
|
5466
5488
|
}
|
|
5467
|
-
|
|
5468
|
-
|
|
5489
|
+
} else if (metadataFilter) {
|
|
5490
|
+
total = (await collection.find(query).toArray()).map((row) => this.parseRow(row)).filter((message) => storage.storageMessageMatchesMetadataFilter(message.content, metadataFilter)).length;
|
|
5491
|
+
} else {
|
|
5492
|
+
total = await collection.countDocuments(query);
|
|
5469
5493
|
}
|
|
5470
5494
|
if (total === 0 && messages.length === 0 && (!include || include.length === 0)) {
|
|
5471
5495
|
return {
|