Skip to content

align mongo storage and vector connection strings and docs - #11728

Merged
graysonhicks merged 6 commits into
mainfrom
fix/11697--mongo-vector-conn-string
Jan 9, 2026
Merged

align mongo storage and vector connection strings and docs#11728
graysonhicks merged 6 commits into
mainfrom
fix/11697--mongo-vector-conn-string

Conversation

@graysonhicks

@graysonhicks graysonhicks commented Jan 8, 2026

Copy link
Copy Markdown
Member

Description

Fix MongoDB connection string parameter inconsistency between MongoDBVector and MongoDBStore.

  • Standardize on uri as the parameter name (correct MongoDB terminology)
  • Add url as a deprecated fallback on MongoDBStore for backward compatibility
  • Add clear error messages when connection string is missing
  • Export MongoDBVectorConfig interface for better TypeScript DX
  • Update all documentation to use uri

Related Issue(s)

Fixes #11697

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update
  • Code refactoring
  • Performance improvement
  • Test update

Checklist

  • I have made corresponding changes to the documentation (if applicable)
  • I have added tests that prove my fix is effective or that my feature works

Summary by CodeRabbit

  • New Features

    • Added optional id parameter for MongoDB storage and vector instances to identify instances.
  • Chores

    • Standardized MongoDB connection option to use uri as the primary field; url is deprecated but still supported for backward compatibility.
    • Improved error messages and documentation/examples to clarify missing or misconfigured MongoDB connection strings.

✏️ Tip: You can customize this high-level summary in your review settings.

@changeset-bot

changeset-bot Bot commented Jan 8, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 187a085

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@mastra/mongodb Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel

vercel Bot commented Jan 8, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Review Updated (UTC)
assistant-ui Ready Ready Preview, Comment Jan 9, 2026 3:23pm
mastra-docs Ready Ready Preview, Comment Jan 9, 2026 3:23pm
mastra-docs-1.x Ready Ready Preview, Comment Jan 9, 2026 3:23pm

@coderabbitai

coderabbitai Bot commented Jan 8, 2026

Copy link
Copy Markdown
Contributor

Walkthrough

This PR standardizes MongoDB connection naming by making uri the primary connection-string option (with url deprecated and kept for backward compatibility), adds an id field to MongoDBStore and MongoDBVector constructor options, and tightens validation/error messages when connection strings are missing.

Changes

Cohort / File(s) Summary
Changeset & Package README
.changeset/quiet-points-brush.md, stores/mongodb/README.md
Added changeset entry; README examples updated to include new id field and use uri in constructor examples.
Docs / Reference
docs/src/content/en/docs/rag/vector-databases.mdx, docs/src/content/en/reference/storage/mongodb.mdx, docs/src/content/en/reference/vectors/mongodb.mdx
Examples and API tables updated: urluri, added id field to constructor examples, deprecation notes for url, updated code samples to use uri.
Type Definitions
stores/mongodb/src/storage/types.ts
Added optional uri?: string to DatabaseConfig and MongoDBDomainConfig; retained url?: string with deprecation JSDoc.
Storage Implementation
stores/mongodb/src/storage/db/index.ts
Resolve connection string from config.uri ?? config.url; validate presence and throw MONGODB_MISSING_URI if absent; improved error payload includes uri, url, dbName.
Storage Tests & Config
stores/mongodb/src/storage/index.test.ts, other test helpers
Tests switched to use TEST_CONFIG.uri; added tests for uri (preferred), url (back-compat), and missing-connection-string negative case; updated helpers and instantiations accordingly.
Vector Implementation
stores/mongodb/src/vector/index.ts
Added MongoDBVectorConfig (includes id, uri, dbName, options), updated constructor to accept the config type, and added runtime validation to require uri.
Vector Tests
stores/mongodb/src/vector/index.test.ts
Added tests for MongoDBVector constructor: accepts standard mongodb://, accepts mongodb+srv://, and throws when uri is missing.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • abhiaiyer91
  • YujohnNattrass
🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The pull request title accurately summarizes the main changes: standardizing MongoDB connection string parameter naming (aligning to 'uri') and updating documentation accordingly.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (6)
stores/mongodb/src/storage/index.test.ts (1)

156-156: Fix references to TEST_CONFIG.url - should be TEST_CONFIG.uri

Multiple test configurations throughout the file reference TEST_CONFIG.url!, but TEST_CONFIG now only defines uri (line 25). This will cause runtime errors.

🐛 Proposed fix

Update all references from TEST_CONFIG.url! to TEST_CONFIG.uri!:

     url: TEST_CONFIG.url!,
+    url: TEST_CONFIG.uri!,

This applies to lines: 156, 169, 174, 179, 251, 264, 277, 623, 649, 657, 667, 680, 714, 728, 740.

Also applies to: 169-169, 174-174, 179-179, 251-251, 264-264, 277-277, 623-623, 649-649, 657-657, 667-667, 680-680, 714-714, 728-728, 740-740

docs/src/content/en/reference/vectors/mongodb.mdx (1)

386-389: Add missing id field to MongoDBVector initialization.

The MongoDBVector constructor requires an id field (as shown in line 27 and in the implementation at stores/mongodb/src/vector/index.ts:73), but it's missing from this example.

🐛 Proposed fix
     vector: new MongoDBVector({
+      id: 'mongodb-vector',
       uri: process.env.MONGODB_URI!,
       dbName: process.env.MONGODB_DB_NAME!,
     }),
docs/src/content/en/reference/storage/mongodb.mdx (4)

36-59: Update Parameters table to document uri instead of url.

The parameters table documents url but the PR standardizes on uri. Update this table to reflect the new API, and optionally add a deprecated url entry for reference.

📝 Suggested documentation fix

Update the first parameter entry:

     {
-      name: "url",
+      name: "id",
       type: "string",
       description:
-        "MongoDB connection string (e.g., mongodb+srv://user:password@cluster.mongodb.net)",
+        "Unique identifier for this storage instance",
       isOptional: false,
     },
     {
-      name: "dbName",
+      name: "uri",
       type: "string",
-      description: "The name of the database you want the storage to use.",
+      description:
+        "MongoDB connection string (e.g., mongodb+srv://user:password@cluster.mongodb.net)",
       isOptional: false,
     },
+    {
+      name: "dbName",
+      type: "string",
+      description: "The name of the database you want the storage to use.",
+      isOptional: false,
+    },

65-85: Update constructor examples to use uri instead of url.

These examples still use the old url parameter. Update them to use uri for consistency with the standardized API.

📝 Suggested documentation fix
 // Basic connection without custom options
 const store1 = new MongoDBStore({
-  url: "mongodb+srv://user:password@cluster.mongodb.net",
+  id: 'mongodb-store',
+  uri: "mongodb+srv://user:password@cluster.mongodb.net",
   dbName: "mastra_storage",
 });

 // Using connection string with options
 const store2 = new MongoDBStore({
-  url: "mongodb+srv://user:password@cluster.mongodb.net",
+  id: 'mongodb-store',
+  uri: "mongodb+srv://user:password@cluster.mongodb.net",
   dbName: "mastra_storage",
   options: {
     retryWrites: true,
     maxPoolSize: 10,
     serverSelectionTimeoutMS: 5000,
     socketTimeoutMS: 45000,
   },
 });

109-127: Update usage examples to use uri instead of url.

These examples still reference MONGODB_URL environment variable and use the url parameter. Update to use uri and MONGODB_URI for consistency.

📝 Suggested documentation fix
 const storage = new MongoDBStore({
-  url: process.env.MONGODB_URL,
+  id: 'mongodb-storage',
+  uri: process.env.MONGODB_URI,
   dbName: process.env.MONGODB_DATABASE,
 });

 // ... later in the file ...

 const storage = new MongoDBStore({
   id: 'mongodb-storage',
-  url: process.env.MONGODB_URL,
+  uri: process.env.MONGODB_URI,
   dbName: process.env.MONGODB_DATABASE,
 });

213-214: Update agent example to use uri instead of url.

This example still uses the old url parameter. Update to use uri for consistency.

📝 Suggested documentation fix
     storage: new MongoDBStore({
-      url: process.env.MONGODB_URI!,
+      id: 'mongodb-storage',
+      uri: process.env.MONGODB_URI!,
       dbName: process.env.MONGODB_DB_NAME!,
     }),
🤖 Fix all issues with AI agents
In @docs/src/content/en/reference/storage/mongodb.mdx:
- Around line 28-30: The docs are inconsistent: examples use the new parameter
name uri while the Parameters table and many examples still reference url;
update the Parameters table to document uri as the primary connection option
(and mark url as deprecated-but-supported), add a short deprecation note about
url for backward compatibility, and replace every code sample and constructor
example that currently uses url with uri (including the Constructor Examples and
all usage snippets) so all examples consistently use uri and refer to url only
in the deprecation note.
🧹 Nitpick comments (2)
.changeset/quiet-points-brush.md (1)

5-5: Improve changeset clarity and add code examples.

The current description could be clearer for developers and should include before/after examples to show the breaking change.

📝 Suggested improvement
-Fix MongoDB connection string parameter naming inconsistency. MongoDBVector now uses uri parameter (correct MongoDB terminology). MongoDBStore now accepts both uri (recommended) and url (deprecated, for backward compatibility). Added clear error messages when connection string is missing.
+Fixed MongoDB connection string parameter naming. Both MongoDBVector and MongoDBStore now use `uri` for the connection string parameter. MongoDBStore maintains backward compatibility with `url` (deprecated). Connection string validation now provides clear error messages.
+
+**MongoDBVector - Breaking change:**
+```ts
+// Before
+new MongoDBVector({
+  url: process.env.MONGODB_URI,
+  dbName: 'mydb'
+})
+
+// After
+new MongoDBVector({
+  id: 'my-vector',
+  uri: process.env.MONGODB_URI,
+  dbName: 'mydb'
+})
+```
+
+**MongoDBStore - Backward compatible:**
+```ts
+// Recommended (new)
+new MongoDBStore({
+  id: 'my-store',
+  uri: process.env.MONGODB_URI,
+  dbName: 'mydb'
+})
+
+// Still works (deprecated)
+new MongoDBStore({
+  id: 'my-store',
+  url: process.env.MONGODB_URI,
+  dbName: 'mydb'
+})
+```

Based on coding guidelines, changeset files should include code examples for breaking changes or new features, show the before/after of the public API, and use direct, scannable formatting.

stores/mongodb/src/vector/index.ts (1)

76-78: Consider using MastraError for consistency.

The URI validation throws a plain Error, while all other error handling in this class uses MastraError with proper error IDs, domains, and categories (see lines 97-105, 112-120, etc.). For consistency and better error handling, consider using MastraError here as well.

♻️ Suggested refactor
     if (!uri) {
-      throw new Error('MongoDBVector requires a connection string. Provide "uri" in the constructor options.');
+      throw new MastraError({
+        id: createVectorErrorId('MONGODB', 'CONSTRUCTOR', 'MISSING_URI'),
+        domain: ErrorDomain.STORAGE,
+        category: ErrorCategory.USER,
+        text: 'MongoDBVector requires a connection string. Provide "uri" in the constructor options.',
+      });
     }
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6f1e233 and 796d2fc.

📒 Files selected for processing (10)
  • .changeset/quiet-points-brush.md
  • docs/src/content/en/docs/rag/vector-databases.mdx
  • docs/src/content/en/reference/storage/mongodb.mdx
  • docs/src/content/en/reference/vectors/mongodb.mdx
  • stores/mongodb/README.md
  • stores/mongodb/src/storage/db/index.ts
  • stores/mongodb/src/storage/index.test.ts
  • stores/mongodb/src/storage/types.ts
  • stores/mongodb/src/vector/index.test.ts
  • stores/mongodb/src/vector/index.ts
🧰 Additional context used
📓 Path-based instructions (6)
**/*.ts?(x)

📄 CodeRabbit inference engine (CLAUDE.md)

**/*.ts?(x): All packages use TypeScript with strict type checking
Use telemetry decorators for observability in component implementations
Support both sync and async operations where applicable in component implementations

Files:

  • stores/mongodb/src/vector/index.test.ts
  • stores/mongodb/src/vector/index.ts
  • stores/mongodb/src/storage/db/index.ts
  • stores/mongodb/src/storage/types.ts
  • stores/mongodb/src/storage/index.test.ts
**/*.test.ts?(x)

📄 CodeRabbit inference engine (CLAUDE.md)

Mock external services in unit tests rather than making real external calls

Files:

  • stores/mongodb/src/vector/index.test.ts
  • stores/mongodb/src/storage/index.test.ts
**/*.{md,mdx}

📄 CodeRabbit inference engine (.cursor/rules/writing-documentation.mdc)

**/*.{md,mdx}: When writing developer documentation, do not use adjectives like 'powerful' or 'built-in' as these read like marketing copy and developers don't like that
When writing developer documentation, do not use 'complete', 'out-of-the-box', 'hands-on', or overly enthusiastic exhortations like 'Check out', 'Learn more', 'Explore'. Do not use words like 'essential' or 'offers'
When writing developer documentation, do not use 'your needs', 'production-ready', 'makes it easy', or 'choose the right...solution' as these are marketing jargon that developers dislike
When writing developer documentation, avoid phrasing like 'without changing your code' or 'automatically handles' that obscures implementation details
In developer documentation, avoid phrasing that glides between benefits without diving into details. Focus on technical specifics and implementation details rather than high-level benefits. For example, avoid sentences like: 'This makes it easy to build AI applications that maintain meaningful conversations and remember important details, whether you're building a simple chatbot or a sophisticated AI assistant'
All H1 headings (# Heading) must use title case format, capitalizing the first letter of each major word. Examples: 'Getting Started', 'Human In-the-Loop Workflow', 'Agent as a Step'

Files:

  • stores/mongodb/README.md
  • docs/src/content/en/docs/rag/vector-databases.mdx
  • docs/src/content/en/reference/vectors/mongodb.mdx
  • docs/src/content/en/reference/storage/mongodb.mdx
**/*.md

📄 CodeRabbit inference engine (CLAUDE.md)

Follow .cursor/rules/writing-documentation.mdc for documentation writing style: avoid marketing language like 'powerful', 'complete', 'out-of-the-box', 'your needs', 'production-ready', and 'makes it easy'; focus on technical details rather than benefits; write for engineers not marketing

Files:

  • stores/mongodb/README.md
**/*{docs,documentation}/**/*.{md,mdx}

📄 CodeRabbit inference engine (.windsurfrules)

**/*{docs,documentation}/**/*.{md,mdx}: When writing developer documentation, do not use adjectives like 'powerful' or 'built-in' as they read like marketing copy
When writing developer documentation, do not use words like 'complete', 'out-of-the-box', 'hands-on', or overly enthusiastic exhortations such as 'Check out', 'Learn more', 'Explore', 'essential', or 'offers'
When writing developer documentation, avoid marketing jargon such as 'your needs', 'production-ready', 'makes it easy', or 'choose the right...solution'
When writing developer documentation, do not use phrases like 'without changing your code' or 'automatically handles' as they glide over implementation details
In developer documentation, avoid phrasing that glides between benefits without diving into details; instead, focus on technical nuts and bolts with specific implementation details rather than abstract benefits

Files:

  • docs/src/content/en/docs/rag/vector-databases.mdx
  • docs/src/content/en/reference/vectors/mongodb.mdx
  • docs/src/content/en/reference/storage/mongodb.mdx
.changeset/*.md

⚙️ CodeRabbit configuration file

.changeset/*.md: Changeset files are really important for keeping track of changes in the project. They'll be used to generate release notes and inform users about updates.

Review the changeset file according to these guidelines:

  • The target audience are developers
  • Write short, direct sentences that anyone can understand. Avoid commit messages, technical jargon, and acronyms. Use action-oriented verbs (Added, Fixed, Improved, Deprecated, Removed)
  • Avoid generic phrases like "Update code", "Miscellaneous improvements", or "Bug fixes"
  • Highlight outcomes! What does change for the end user? Do not focus on internal implementation details
  • Add context like links to issues or PRs when relevant
  • If the change is a breaking change or is adding a new feature, ensure that a code example is provided. This code example should show the public API usage (the before and after). Do not show code examples of internal implementation details.
  • Keep the formatting easy-to-read and scannable. If necessary, use bullet points or multiple paragraphs (Use bold text as the heading for these sections, do not use markdown headings).
  • For larger, more substantial changes, also answer the "Why" behind the changes
  • Each changeset file contains a YAML frontmatter at the top. It will be one or more package names followed by a colon and the type of change (patch, minor, major). Do not modify this frontmatter. Check that the description inside the changeset file only applies to the packages listed in the frontmatter. Do not allow descriptions that mention changes to packages not listed in the frontmatter. In these cases, the user must create a separate changeset file for those packages.

In case of a guideline violation ALWAYS mark your comment as potential_issue.

Files:

  • .changeset/quiet-points-brush.md
🧠 Learnings (2)
📚 Learning: 2025-11-24T16:42:04.244Z
Learnt from: CR
Repo: mastra-ai/mastra PR: 0
File: packages/codemod/AGENTS.md:0-0
Timestamp: 2025-11-24T16:42:04.244Z
Learning: Applies to packages/codemod/src/test/__fixtures__/**/*.ts : Create test fixtures by copying examples DIRECTLY from migration guides in `docs/src/content/en/guides/migrations/upgrade-to-v1/` without hallucinating or inventing changes

Applied to files:

  • stores/mongodb/src/vector/index.test.ts
  • stores/mongodb/src/storage/index.test.ts
📚 Learning: 2025-11-24T16:42:04.244Z
Learnt from: CR
Repo: mastra-ai/mastra PR: 0
File: packages/codemod/AGENTS.md:0-0
Timestamp: 2025-11-24T16:42:04.244Z
Learning: Applies to packages/codemod/src/test/__fixtures__/**/*.ts : In output fixtures, ensure all NEGATIVE test cases remain EXACTLY IDENTICAL to their input fixture counterparts to verify the codemod only transforms intended patterns

Applied to files:

  • stores/mongodb/src/storage/index.test.ts
🧬 Code graph analysis (2)
stores/mongodb/src/vector/index.test.ts (1)
stores/mongodb/src/vector/index.ts (1)
  • MongoDBVector (59-865)
stores/mongodb/src/storage/index.test.ts (1)
stores/mongodb/src/storage/index.ts (1)
  • MongoDBStore (41-95)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (6)
stores/mongodb/src/storage/index.test.ts (1)

29-60: LGTM! Comprehensive test coverage for the uri/url parameter handling.

The new test suite properly validates:

  • The recommended uri parameter
  • Backward compatibility with deprecated url parameter
  • Clear error messaging when neither is provided
docs/src/content/en/docs/rag/vector-databases.mdx (1)

36-40: LGTM! Documentation properly reflects the updated API.

The example correctly shows the new id field and uses uri for the connection string, aligning with the standardized naming.

stores/mongodb/src/vector/index.test.ts (1)

5-36: LGTM! Comprehensive test coverage for MongoDBVector constructor.

The tests properly validate:

  • Standard MongoDB connection strings (mongodb://)
  • MongoDB Atlas connection strings (mongodb+srv://)
  • Clear error messaging when uri is missing

The test structure is clear and follows existing patterns.

stores/mongodb/src/storage/db/index.ts (2)

37-47: LGTM! Solid implementation of uri/url fallback with clear error handling.

The implementation:

  • Correctly prioritizes uri over url with fallback
  • Provides clear, actionable error message when connection string is missing
  • Maintains backward compatibility

62-62: Good defensive error detail logging.

Including both uri and url fields in error details aids debugging when configuration issues occur.

stores/mongodb/src/storage/types.ts (1)

68-78: Connection string validation is properly handled in the implementation.

Both uri and url optional fields are correctly validated:

  • At least one is required: resolveMongoDBConfig enforces this at line 38-47 (db/index.ts), throwing MISSING_URI if neither is provided
  • Precedence is clear: uri takes priority with the ?? operator (line 38)
  • Both provided: uri is used, url is ignored as fallback

The implementation correctly handles all edge cases, and the type definition appropriately allows both for backward compatibility during the deprecation period.

Comment thread docs/src/content/en/reference/storage/mongodb.mdx

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
stores/mongodb/src/storage/index.test.ts (1)

93-127: Config validation tests should include uri-based valid configs.

The valid configs array only includes url-based configurations (lines 96, 102, 121). While these test backward compatibility, you should also add test cases using the new uri parameter to explicitly validate the preferred approach.

➕ Add uri-based valid config tests
   validConfigs: [
+    {
+      description: 'URI/dbName config',
+      config: { id: 'test-store', uri: 'mongodb://localhost:27017', dbName: 'test-db' },
+    },
+    {
+      description: 'URI/dbName with options',
+      config: {
+        id: 'test-store',
+        uri: 'mongodb://localhost:27017',
+        dbName: 'test-db',
+        options: { maxPoolSize: 50, minPoolSize: 5 },
+      },
+    },
     {
       description: 'URL/dbName config',
       config: { id: 'test-store', url: 'mongodb://localhost:27017', dbName: 'test-db' },
     },
🧹 Nitpick comments (3)
docs/src/content/en/reference/storage/mongodb.mdx (1)

12-12: Avoid vague descriptor in documentation.

The phrase "scalable storage solution" reads as a marketing claim without technical specifics. Consider rephrasing to focus on concrete capabilities.

✍️ Suggested alternative
-The MongoDB storage implementation provides a scalable storage solution using MongoDB databases with support for both document storage and vector operations.
+The MongoDB storage implementation uses MongoDB databases and supports both document storage and vector operations.

As per coding guidelines, avoid marketing language in developer documentation.

stores/mongodb/src/storage/index.test.ts (2)

128-144: Invalid config tests also need uri-based cases.

Similar to the valid configs, the invalid configs should include test cases that use uri instead of only testing the deprecated url parameter (lines 131, 136, 141).

➕ Add uri-based invalid config tests
   invalidConfigs: [
+    {
+      description: 'empty uri without connectorHandler',
+      config: { id: 'test-store', uri: '', dbName: 'test-db' },
+      expectedError: /connection string|uri.*url/i,
+    },
     {
       description: 'empty url without connectorHandler',
       config: { id: 'test-store', url: '', dbName: 'test-db' },
       expectedError: /connection string|uri.*url/i,
     },

247-259: MongoDB-specific tests still use url parameter.

While testing backward compatibility is valuable, these MongoDB-specific connection tests (lines 251, 264, 277) only use the deprecated url parameter. Consider adding equivalent tests using uri to validate the primary parameter works with these connection scenarios.

➕ Add uri-based connection tests

Add tests that mirror these connection scenarios but use uri instead:

it('should handle MongoDB Atlas connection strings with uri', () => {
  const atlasConfig = {
    id: 'mongodb-atlas-uri-test',
    uri: 'mongodb+srv://user:pass@cluster.mongodb.net/',
    dbName: 'test-db',
    options: {
      retryWrites: true,
      w: 'majority' as const,
    },
  };
  expect(() => new MongoDBStore(atlasConfig)).not.toThrow();
});
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 796d2fc and 7ad9c72.

📒 Files selected for processing (2)
  • docs/src/content/en/reference/storage/mongodb.mdx
  • stores/mongodb/src/storage/index.test.ts
🧰 Additional context used
📓 Path-based instructions (4)
**/*.ts?(x)

📄 CodeRabbit inference engine (CLAUDE.md)

**/*.ts?(x): All packages use TypeScript with strict type checking
Use telemetry decorators for observability in component implementations
Support both sync and async operations where applicable in component implementations

Files:

  • stores/mongodb/src/storage/index.test.ts
**/*.test.ts?(x)

📄 CodeRabbit inference engine (CLAUDE.md)

Mock external services in unit tests rather than making real external calls

Files:

  • stores/mongodb/src/storage/index.test.ts
**/*.{md,mdx}

📄 CodeRabbit inference engine (.cursor/rules/writing-documentation.mdc)

**/*.{md,mdx}: When writing developer documentation, do not use adjectives like 'powerful' or 'built-in' as these read like marketing copy and developers don't like that
When writing developer documentation, do not use 'complete', 'out-of-the-box', 'hands-on', or overly enthusiastic exhortations like 'Check out', 'Learn more', 'Explore'. Do not use words like 'essential' or 'offers'
When writing developer documentation, do not use 'your needs', 'production-ready', 'makes it easy', or 'choose the right...solution' as these are marketing jargon that developers dislike
When writing developer documentation, avoid phrasing like 'without changing your code' or 'automatically handles' that obscures implementation details
In developer documentation, avoid phrasing that glides between benefits without diving into details. Focus on technical specifics and implementation details rather than high-level benefits. For example, avoid sentences like: 'This makes it easy to build AI applications that maintain meaningful conversations and remember important details, whether you're building a simple chatbot or a sophisticated AI assistant'
All H1 headings (# Heading) must use title case format, capitalizing the first letter of each major word. Examples: 'Getting Started', 'Human In-the-Loop Workflow', 'Agent as a Step'

Files:

  • docs/src/content/en/reference/storage/mongodb.mdx
**/*{docs,documentation}/**/*.{md,mdx}

📄 CodeRabbit inference engine (.windsurfrules)

**/*{docs,documentation}/**/*.{md,mdx}: When writing developer documentation, do not use adjectives like 'powerful' or 'built-in' as they read like marketing copy
When writing developer documentation, do not use words like 'complete', 'out-of-the-box', 'hands-on', or overly enthusiastic exhortations such as 'Check out', 'Learn more', 'Explore', 'essential', or 'offers'
When writing developer documentation, avoid marketing jargon such as 'your needs', 'production-ready', 'makes it easy', or 'choose the right...solution'
When writing developer documentation, do not use phrases like 'without changing your code' or 'automatically handles' as they glide over implementation details
In developer documentation, avoid phrasing that glides between benefits without diving into details; instead, focus on technical nuts and bolts with specific implementation details rather than abstract benefits

Files:

  • docs/src/content/en/reference/storage/mongodb.mdx
🧠 Learnings (1)
📚 Learning: 2025-11-24T16:42:04.244Z
Learnt from: CR
Repo: mastra-ai/mastra PR: 0
File: packages/codemod/AGENTS.md:0-0
Timestamp: 2025-11-24T16:42:04.244Z
Learning: Applies to packages/codemod/src/test/__fixtures__/**/*.ts : Create test fixtures by copying examples DIRECTLY from migration guides in `docs/src/content/en/guides/migrations/upgrade-to-v1/` without hallucinating or inventing changes

Applied to files:

  • stores/mongodb/src/storage/index.test.ts
🧬 Code graph analysis (1)
stores/mongodb/src/storage/index.test.ts (2)
stores/mongodb/src/storage/index.ts (2)
  • MongoDBStore (41-95)
  • MemoryStorageMongoDB (16-16)
stores/mongodb/src/storage/domains/memory/index.ts (1)
  • MemoryStorageMongoDB (27-899)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: Validate build outputs
  • GitHub Check: Lint
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (16)
docs/src/content/en/reference/storage/mongodb.mdx (7)

28-31: LGTM! Clear example with updated parameters.

The basic usage example correctly demonstrates the new uri parameter and includes the id field. The change aligns with the PR objectives to standardize on uri as the parameter name.


39-51: Good addition of deprecation information.

The parameters table correctly lists uri as the primary parameter and url as deprecated with backward compatibility support. The descriptions are clear and technical.


68-70: Clear deprecation notice.

The deprecation notice appropriately informs users to use uri in new code while maintaining backward compatibility for url. The messaging is straightforward and actionable.


80-96: Examples correctly updated to use uri.

Both constructor examples now use uri instead of url, demonstrating the recommended approach. The examples cover basic and advanced configurations appropriately.


120-147: Initialization section properly updated.

All examples in the initialization section correctly use uri and include the id field where appropriate. The code examples are consistent with the API changes.


163-166: MongoDBVector example correctly updated.

The vector store example now includes both id and uri parameters, aligning with the standardization effort described in the PR objectives.


224-224: Agent memory example updated correctly.

The agent configuration example uses uri consistently with the rest of the documentation updates.

stores/mongodb/src/storage/index.test.ts (9)

25-25: LGTM! Test configuration updated correctly.

The TEST_CONFIG now uses uri instead of url, aligning with the standardization effort.


29-60: Excellent test coverage for the issue fix.

The new test suite comprehensively validates:

  1. Acceptance of the new uri parameter
  2. Backward compatibility with the deprecated url parameter
  3. Clear error messaging when neither parameter is provided

The tests directly address GitHub issue #11697 and provide good regression protection.


64-64: MongoClient instantiation correctly updated.

The createConnectorHandler helper now uses TEST_CONFIG.uri to create the MongoClient, consistent with the parameter name change.


156-159: Store creation updated correctly for client acceptance tests.

The test now uses uri from TEST_CONFIG to create the store, consistent with the new parameter naming.


168-181: Domain creation helpers correctly updated.

All three domain test helpers (MemoryStorageMongoDB, WorkflowsStorageMongoDB, ScoresStorageMongoDB) now use uri instead of url.


623-623: MongoClient creation in helper updated correctly.

The mongoIndexExists helper now uses TEST_CONFIG.uri to create the MongoClient for index checking operations.


649-687: Store-level index tests correctly use uri.

All store creation helpers for index testing (createDefaultStore, createStoreWithSkipDefaults, createStoreWithCustomIndexes, createStoreWithInvalidTable) consistently use uri from TEST_CONFIG.


713-747: Domain-level index tests correctly use uri.

All domain creation helpers for index testing consistently use uri from TEST_CONFIG, maintaining consistency with the store-level tests.


52-59: The regex pattern /uri.*url|connection/i correctly matches the actual error message thrown by the implementation: "MongoDBStore requires a connection string. Provide "uri" (recommended) or "url" in the constructor options."

The pattern is appropriately designed, not overly broad. It matches both "uri" followed by "url" (the two parameter names) and "connection" (the context of the validation), which are both present in the actual error message. There are no unintended error messages in the code path that would be incorrectly matched by this pattern.

Likely an incorrect or invalid review comment.

@graysonhicks
graysonhicks merged commit 80ba4c1 into main Jan 9, 2026
41 of 42 checks passed
@graysonhicks
graysonhicks deleted the fix/11697--mongo-vector-conn-string branch January 9, 2026 16:04
@coderabbitai coderabbitai Bot mentioned this pull request Jan 14, 2026
9 tasks
DevZonayed pushed a commit to DevZonayed/nexalance-skill-mastra-ai-mastra that referenced this pull request Aug 17, 2026
…#11728)

## Description

Fix MongoDB connection string parameter inconsistency between
`MongoDBVector` and `MongoDBStore`.

- Standardize on `uri` as the parameter name (correct MongoDB
terminology)
- Add `url` as a deprecated fallback on `MongoDBStore` for backward
compatibility
- Add clear error messages when connection string is missing
- Export `MongoDBVectorConfig` interface for better TypeScript DX
- Update all documentation to use `uri`

## Related Issue(s)

Fixes mastra-ai#11697

## Type of Change

- [x] Bug fix (non-breaking change that fixes an issue)
- [ ] New feature (non-breaking change that adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to change)
- [x] Documentation update
- [ ] Code refactoring
- [ ] Performance improvement
- [x] Test update

## Checklist

- [x] I have made corresponding changes to the documentation (if
applicable)
- [x] I have added tests that prove my fix is effective or that my
feature works

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **New Features**
* Added optional id parameter for MongoDB storage and vector instances
to identify instances.

* **Chores**
* Standardized MongoDB connection option to use uri as the primary
field; url is deprecated but still supported for backward compatibility.
* Improved error messages and documentation/examples to clarify missing
or misconfigured MongoDB connection strings.

<sub>✏️ Tip: You can customize this high-level summary in your review
settings.</sub>
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Mongo Vector TypeError: Cannot read properties of undefined (reading 'startsWith') at <unknown>

2 participants