@mastra/mongodb 0.1.0-alpha.1 → 0.10.1-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.
@@ -1,23 +1,23 @@
1
1
 
2
- > @mastra/mongodb@0.1.0-alpha.1 build /home/runner/work/mastra/mastra/stores/mongodb
2
+ > @mastra/mongodb@0.10.1-alpha.0 build /home/runner/work/mastra/mastra/stores/mongodb
3
3
  > tsup src/index.ts --format esm,cjs --experimental-dts --clean --treeshake=smallest --splitting
4
4
 
5
5
  CLI Building entry: src/index.ts
6
6
  CLI Using tsconfig: tsconfig.json
7
7
  CLI tsup v8.4.0
8
8
  TSC Build start
9
- TSC ⚡️ Build success in 7075ms
9
+ TSC ⚡️ Build success in 11126ms
10
10
  DTS Build start
11
11
  CLI Target: es2022
12
12
  Analysis will use the bundled TypeScript version 5.8.3
13
13
  Writing package typings: /home/runner/work/mastra/mastra/stores/mongodb/dist/_tsup-dts-rollup.d.ts
14
14
  Analysis will use the bundled TypeScript version 5.8.3
15
15
  Writing package typings: /home/runner/work/mastra/mastra/stores/mongodb/dist/_tsup-dts-rollup.d.cts
16
- DTS ⚡️ Build success in 8116ms
16
+ DTS ⚡️ Build success in 13746ms
17
17
  CLI Cleaning output folder
18
18
  ESM Build start
19
19
  CJS Build start
20
- ESM dist/index.js 18.05 KB
21
- ESM ⚡️ Build success in 634ms
22
- CJS dist/index.cjs 18.11 KB
23
- CJS ⚡️ Build success in 629ms
20
+ ESM dist/index.js 32.81 KB
21
+ ESM ⚡️ Build success in 1273ms
22
+ CJS dist/index.cjs 32.93 KB
23
+ CJS ⚡️ Build success in 1273ms
package/CHANGELOG.md CHANGED
@@ -1,5 +1,43 @@
1
1
  # @mastra/mongodb
2
2
 
3
+ ## 0.10.1-alpha.0
4
+
5
+ ### Patch Changes
6
+
7
+ - fcc915f: Support MongoDB database as store
8
+ - Updated dependencies [6d16390]
9
+ - Updated dependencies [1e4a421]
10
+ - @mastra/core@0.10.1-alpha.0
11
+
12
+ ## 0.10.0
13
+
14
+ ### Minor Changes
15
+
16
+ - 83da932: Move @mastra/core to peerdeps
17
+
18
+ ### Patch Changes
19
+
20
+ - d0ee3c6: Change all public functions and constructors in vector stores to use named args and prepare to phase out positional args
21
+ - a7292b0: BREAKING(@mastra/core, all vector stores): Vector store breaking changes (remove deprecated functions and positional arguments)
22
+ - Updated dependencies [b3a3d63]
23
+ - Updated dependencies [344f453]
24
+ - Updated dependencies [0a3ae6d]
25
+ - Updated dependencies [95911be]
26
+ - Updated dependencies [f53a6ac]
27
+ - Updated dependencies [5eb5a99]
28
+ - Updated dependencies [7e632c5]
29
+ - Updated dependencies [1e9fbfa]
30
+ - Updated dependencies [eabdcd9]
31
+ - Updated dependencies [90be034]
32
+ - Updated dependencies [99f050a]
33
+ - Updated dependencies [d0ee3c6]
34
+ - Updated dependencies [b2ae5aa]
35
+ - Updated dependencies [23f258c]
36
+ - Updated dependencies [a7292b0]
37
+ - Updated dependencies [0dcb9f0]
38
+ - Updated dependencies [2672a05]
39
+ - @mastra/core@0.10.0
40
+
3
41
  ## 0.1.0-alpha.1
4
42
 
5
43
  ### Minor Changes
package/README.md CHANGED
@@ -56,6 +56,40 @@ const results = await vectorDB.query({
56
56
  await vectorDB.disconnect();
57
57
  ```
58
58
 
59
+ ### Storage
60
+
61
+ ```typescript
62
+ import { MongoDBStore } from '@mastra/mongodb';
63
+
64
+ const store = new MongoDBStore({
65
+ uri: 'mongodb://mongodb:mongodb@localhost:27018/?authSource=admin&directConnection=true',
66
+ dbName: 'mastra',
67
+ });
68
+
69
+ // Create a thread
70
+ await store.saveThread({
71
+ id: 'thread-123',
72
+ resourceId: 'resource-456',
73
+ title: 'My Thread',
74
+ metadata: { key: 'value' },
75
+ });
76
+
77
+ // Add messages to thread
78
+ await store.saveMessages([
79
+ {
80
+ id: 'msg-789',
81
+ threadId: 'thread-123',
82
+ role: 'user',
83
+ type: 'text',
84
+ content: [{ type: 'text', text: 'Hello' }],
85
+ },
86
+ ]);
87
+
88
+ // Query threads and messages
89
+ const savedThread = await store.getThread('thread-123');
90
+ const messages = await store.getMessages('thread-123');
91
+ ```
92
+
59
93
  ## Configuration
60
94
 
61
95
  The MongoDB vector store is initialized with:
@@ -83,6 +117,13 @@ const vectorDB = new MongoDBVector({
83
117
  - Collection (index) management: create, list, describe, delete
84
118
  - Atlas Search readiness checks for reliable testing
85
119
 
120
+ ### Storage Features
121
+
122
+ - Thread and message storage with JSON support
123
+ - Efficient batch operations
124
+ - Rich metadata support
125
+ - Timestamp tracking
126
+
86
127
  ## Supported Filter Operators
87
128
 
88
129
  - Comparison: `$eq`, `$ne`, `$gt`, `$gte`, `$lt`, `$lte`
@@ -121,6 +162,15 @@ The following distance metrics are supported:
121
162
  - `deleteIndex(indexName)`: Delete a collection
122
163
  - `disconnect()`: Close the MongoDB connection
123
164
 
165
+ ## Storage Methods
166
+
167
+ - `saveThread(thread)`: Create or update a thread
168
+ - `getThread(threadId)`: Get a thread by ID
169
+ - `deleteThread(threadId)`: Delete a thread and its messages
170
+ - `saveMessages(messages)`: Save multiple messages in a transaction
171
+ - `getMessages(threadId)`: Get all messages for a thread
172
+ - `deleteMessages(messageIds)`: Delete specific messages
173
+
124
174
  ## Query Response Format
125
175
 
126
176
  Each query result includes:
@@ -3,15 +3,23 @@ import type { CreateIndexParams } from '@mastra/core/vector';
3
3
  import type { DeleteIndexParams } from '@mastra/core/vector';
4
4
  import type { DeleteVectorParams } from '@mastra/core/vector';
5
5
  import type { DescribeIndexParams } from '@mastra/core/vector';
6
+ import type { EvalRow } from '@mastra/core/storage';
6
7
  import type { IndexStats } from '@mastra/core/vector';
8
+ import { MastraStorage } from '@mastra/core/storage';
7
9
  import { MastraVector } from '@mastra/core/vector';
10
+ import type { MessageType } from '@mastra/core/memory';
8
11
  import type { MongoClientOptions } from 'mongodb';
9
12
  import type { OperatorSupport } from '@mastra/core/vector/filter';
10
13
  import type { QueryResult } from '@mastra/core/vector';
11
14
  import type { QueryVectorParams } from '@mastra/core/vector';
15
+ import type { StorageGetMessagesArg } from '@mastra/core/storage';
16
+ import type { StorageThreadType } from '@mastra/core/memory';
17
+ import type { TABLE_NAMES } from '@mastra/core/storage';
12
18
  import type { UpdateVectorParams } from '@mastra/core/vector';
13
19
  import type { UpsertVectorParams } from '@mastra/core/vector';
14
20
  import type { VectorFilter } from '@mastra/core/vector/filter';
21
+ import type { WorkflowRun } from '@mastra/core/storage';
22
+ import type { WorkflowRunState } from '@mastra/core/workflows';
15
23
 
16
24
  /**
17
25
  * Vector store specific prompt that details supported operators and examples.
@@ -21,6 +29,13 @@ declare const MONGODB_PROMPT = "When querying MongoDB Vector, you can ONLY use t
21
29
  export { MONGODB_PROMPT }
22
30
  export { MONGODB_PROMPT as MONGODB_PROMPT_alias_1 }
23
31
 
32
+ declare interface MongoDBConfig {
33
+ url: string;
34
+ dbName: string;
35
+ }
36
+ export { MongoDBConfig }
37
+ export { MongoDBConfig as MongoDBConfig_alias_1 }
38
+
24
39
  /**
25
40
  * Translator for MongoDB filter queries.
26
41
  * Maintains MongoDB-compatible syntax while ensuring proper validation
@@ -48,6 +63,94 @@ declare interface MongoDBQueryVectorParams extends QueryVectorParams {
48
63
  export { MongoDBQueryVectorParams }
49
64
  export { MongoDBQueryVectorParams as MongoDBQueryVectorParams_alias_1 }
50
65
 
66
+ declare class MongoDBStore extends MastraStorage {
67
+ #private;
68
+ constructor(config: MongoDBConfig);
69
+ private getConnection;
70
+ private getCollection;
71
+ createTable(): Promise<void>;
72
+ clearTable({ tableName }: {
73
+ tableName: TABLE_NAMES;
74
+ }): Promise<void>;
75
+ insert({ tableName, record }: {
76
+ tableName: TABLE_NAMES;
77
+ record: Record<string, any>;
78
+ }): Promise<void>;
79
+ batchInsert({ tableName, records }: {
80
+ tableName: TABLE_NAMES;
81
+ records: Record<string, any>[];
82
+ }): Promise<void>;
83
+ load<R>({ tableName, keys }: {
84
+ tableName: TABLE_NAMES;
85
+ keys: Record<string, string>;
86
+ }): Promise<R | null>;
87
+ getThreadById({ threadId }: {
88
+ threadId: string;
89
+ }): Promise<StorageThreadType | null>;
90
+ getThreadsByResourceId({ resourceId }: {
91
+ resourceId: string;
92
+ }): Promise<StorageThreadType[]>;
93
+ saveThread({ thread }: {
94
+ thread: StorageThreadType;
95
+ }): Promise<StorageThreadType>;
96
+ updateThread({ id, title, metadata, }: {
97
+ id: string;
98
+ title: string;
99
+ metadata: Record<string, unknown>;
100
+ }): Promise<StorageThreadType>;
101
+ deleteThread({ threadId }: {
102
+ threadId: string;
103
+ }): Promise<void>;
104
+ getMessages<T = unknown>({ threadId, selectBy }: StorageGetMessagesArg): Promise<T[]>;
105
+ saveMessages({ messages }: {
106
+ messages: MessageType[];
107
+ }): Promise<MessageType[]>;
108
+ getTraces({ name, scope, page, perPage, attributes, filters, }?: {
109
+ name?: string;
110
+ scope?: string;
111
+ page: number;
112
+ perPage: number;
113
+ attributes?: Record<string, string>;
114
+ filters?: Record<string, any>;
115
+ }): Promise<any[]>;
116
+ getWorkflowRuns({ workflowName, fromDate, toDate, limit, offset, }?: {
117
+ workflowName?: string;
118
+ fromDate?: Date;
119
+ toDate?: Date;
120
+ limit?: number;
121
+ offset?: number;
122
+ }): Promise<{
123
+ runs: Array<{
124
+ workflowName: string;
125
+ runId: string;
126
+ snapshot: WorkflowRunState | string;
127
+ createdAt: Date;
128
+ updatedAt: Date;
129
+ }>;
130
+ total: number;
131
+ }>;
132
+ getEvalsByAgentName(agentName: string, type?: 'test' | 'live'): Promise<EvalRow[]>;
133
+ persistWorkflowSnapshot({ workflowName, runId, snapshot, }: {
134
+ workflowName: string;
135
+ runId: string;
136
+ snapshot: WorkflowRunState;
137
+ }): Promise<void>;
138
+ loadWorkflowSnapshot({ workflowName, runId, }: {
139
+ workflowName: string;
140
+ runId: string;
141
+ }): Promise<WorkflowRunState | null>;
142
+ getWorkflowRunById({ runId, workflowName, }: {
143
+ runId: string;
144
+ workflowName?: string;
145
+ }): Promise<WorkflowRun | null>;
146
+ private parseWorkflowRun;
147
+ private parseRow;
148
+ private transformEvalRow;
149
+ close(): Promise<void>;
150
+ }
151
+ export { MongoDBStore }
152
+ export { MongoDBStore as MongoDBStore_alias_1 }
153
+
51
154
  declare interface MongoDBUpsertVectorParams extends UpsertVectorParams {
52
155
  documents?: string[];
53
156
  }
@@ -3,15 +3,23 @@ import type { CreateIndexParams } from '@mastra/core/vector';
3
3
  import type { DeleteIndexParams } from '@mastra/core/vector';
4
4
  import type { DeleteVectorParams } from '@mastra/core/vector';
5
5
  import type { DescribeIndexParams } from '@mastra/core/vector';
6
+ import type { EvalRow } from '@mastra/core/storage';
6
7
  import type { IndexStats } from '@mastra/core/vector';
8
+ import { MastraStorage } from '@mastra/core/storage';
7
9
  import { MastraVector } from '@mastra/core/vector';
10
+ import type { MessageType } from '@mastra/core/memory';
8
11
  import type { MongoClientOptions } from 'mongodb';
9
12
  import type { OperatorSupport } from '@mastra/core/vector/filter';
10
13
  import type { QueryResult } from '@mastra/core/vector';
11
14
  import type { QueryVectorParams } from '@mastra/core/vector';
15
+ import type { StorageGetMessagesArg } from '@mastra/core/storage';
16
+ import type { StorageThreadType } from '@mastra/core/memory';
17
+ import type { TABLE_NAMES } from '@mastra/core/storage';
12
18
  import type { UpdateVectorParams } from '@mastra/core/vector';
13
19
  import type { UpsertVectorParams } from '@mastra/core/vector';
14
20
  import type { VectorFilter } from '@mastra/core/vector/filter';
21
+ import type { WorkflowRun } from '@mastra/core/storage';
22
+ import type { WorkflowRunState } from '@mastra/core/workflows';
15
23
 
16
24
  /**
17
25
  * Vector store specific prompt that details supported operators and examples.
@@ -21,6 +29,13 @@ declare const MONGODB_PROMPT = "When querying MongoDB Vector, you can ONLY use t
21
29
  export { MONGODB_PROMPT }
22
30
  export { MONGODB_PROMPT as MONGODB_PROMPT_alias_1 }
23
31
 
32
+ declare interface MongoDBConfig {
33
+ url: string;
34
+ dbName: string;
35
+ }
36
+ export { MongoDBConfig }
37
+ export { MongoDBConfig as MongoDBConfig_alias_1 }
38
+
24
39
  /**
25
40
  * Translator for MongoDB filter queries.
26
41
  * Maintains MongoDB-compatible syntax while ensuring proper validation
@@ -48,6 +63,94 @@ declare interface MongoDBQueryVectorParams extends QueryVectorParams {
48
63
  export { MongoDBQueryVectorParams }
49
64
  export { MongoDBQueryVectorParams as MongoDBQueryVectorParams_alias_1 }
50
65
 
66
+ declare class MongoDBStore extends MastraStorage {
67
+ #private;
68
+ constructor(config: MongoDBConfig);
69
+ private getConnection;
70
+ private getCollection;
71
+ createTable(): Promise<void>;
72
+ clearTable({ tableName }: {
73
+ tableName: TABLE_NAMES;
74
+ }): Promise<void>;
75
+ insert({ tableName, record }: {
76
+ tableName: TABLE_NAMES;
77
+ record: Record<string, any>;
78
+ }): Promise<void>;
79
+ batchInsert({ tableName, records }: {
80
+ tableName: TABLE_NAMES;
81
+ records: Record<string, any>[];
82
+ }): Promise<void>;
83
+ load<R>({ tableName, keys }: {
84
+ tableName: TABLE_NAMES;
85
+ keys: Record<string, string>;
86
+ }): Promise<R | null>;
87
+ getThreadById({ threadId }: {
88
+ threadId: string;
89
+ }): Promise<StorageThreadType | null>;
90
+ getThreadsByResourceId({ resourceId }: {
91
+ resourceId: string;
92
+ }): Promise<StorageThreadType[]>;
93
+ saveThread({ thread }: {
94
+ thread: StorageThreadType;
95
+ }): Promise<StorageThreadType>;
96
+ updateThread({ id, title, metadata, }: {
97
+ id: string;
98
+ title: string;
99
+ metadata: Record<string, unknown>;
100
+ }): Promise<StorageThreadType>;
101
+ deleteThread({ threadId }: {
102
+ threadId: string;
103
+ }): Promise<void>;
104
+ getMessages<T = unknown>({ threadId, selectBy }: StorageGetMessagesArg): Promise<T[]>;
105
+ saveMessages({ messages }: {
106
+ messages: MessageType[];
107
+ }): Promise<MessageType[]>;
108
+ getTraces({ name, scope, page, perPage, attributes, filters, }?: {
109
+ name?: string;
110
+ scope?: string;
111
+ page: number;
112
+ perPage: number;
113
+ attributes?: Record<string, string>;
114
+ filters?: Record<string, any>;
115
+ }): Promise<any[]>;
116
+ getWorkflowRuns({ workflowName, fromDate, toDate, limit, offset, }?: {
117
+ workflowName?: string;
118
+ fromDate?: Date;
119
+ toDate?: Date;
120
+ limit?: number;
121
+ offset?: number;
122
+ }): Promise<{
123
+ runs: Array<{
124
+ workflowName: string;
125
+ runId: string;
126
+ snapshot: WorkflowRunState | string;
127
+ createdAt: Date;
128
+ updatedAt: Date;
129
+ }>;
130
+ total: number;
131
+ }>;
132
+ getEvalsByAgentName(agentName: string, type?: 'test' | 'live'): Promise<EvalRow[]>;
133
+ persistWorkflowSnapshot({ workflowName, runId, snapshot, }: {
134
+ workflowName: string;
135
+ runId: string;
136
+ snapshot: WorkflowRunState;
137
+ }): Promise<void>;
138
+ loadWorkflowSnapshot({ workflowName, runId, }: {
139
+ workflowName: string;
140
+ runId: string;
141
+ }): Promise<WorkflowRunState | null>;
142
+ getWorkflowRunById({ runId, workflowName, }: {
143
+ runId: string;
144
+ workflowName?: string;
145
+ }): Promise<WorkflowRun | null>;
146
+ private parseWorkflowRun;
147
+ private parseRow;
148
+ private transformEvalRow;
149
+ close(): Promise<void>;
150
+ }
151
+ export { MongoDBStore }
152
+ export { MongoDBStore as MongoDBStore_alias_1 }
153
+
51
154
  declare interface MongoDBUpsertVectorParams extends UpsertVectorParams {
52
155
  documents?: string[];
53
156
  }