Skip to content

feat: update deps and support mongo v7 #369

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 31, 2025
Merged

Conversation

adborroto
Copy link
Contributor

Signed-off-by: Alejandro Dominguez [email protected]

Note - Since this is a public repository, make sure that we're not publishing private data in the code, commit comments, or this PR.

Note for reviewers - Please add a 2nd reviewer if the PR affects more than 15 files or 100 lines (not counting
package-lock.json), if it incurs significant risk, or if it is going through a 2nd review+fix cycle.

📚 Context/Description Behind The Change

This PR updates the MongoDB driver and related dependencies to their latest stable versions, along with necessary code modifications to support these updates. The changes include modernizing the test suite to use async/await syntax consistently and updating BSON handling.

Dependency updates:

  • bson: ^6.10.3
  • mongodb: ^6.15.0
  • mongodb-memory-server: ^10.1.4
  • mongoist: ^4.0.1
  • mongoose: ^8.12.2

Code changes:

  • Converted database operations to use async/await syntax consistently
  • Updated test suite to use modern MongoDB connection patterns
  • Replaced deprecated mongo.ObjectID with new ObjectId()
  • Updated import statements to use correct BSON types

Breaking Changes

  • Requires Node.js version compatible with MongoDB driver 6.x
  • BSON types must now be consistently from version 6.x

🚨 Potential Risks & What To Monitor After Deployment

Not retrocompatible, breaking changes

🧑‍🔬 How Has This Been Tested?

🚚 Release Plan

Copy link

coderabbitai bot commented Mar 28, 2025

Walkthrough

The pull request introduces updates to dependency versions and improves asynchronous handling in the test suites. In the package.json file, the testing script for the native driver is simplified and several dependencies such as bson, mongodb, mongodb-memory-server, mongoist, and mongoose are updated to newer versions. In the test suites, the beforeAll hooks in multiple files now await the promise returned by dbUtils.start(), ensuring that the MongoDB in-memory server is fully initiated before tests run. Additionally, the connection logic in test/support/db.ts has been streamlined to remove conditional version-based logic by directly using MongoClient.connect() and by switching to MongoMemoryServer.create(). The ObjectId is now imported from bson rather than from mongoist, modernizing the instantiation approach.

Sequence Diagram(s)

sequenceDiagram
    participant T as Test Runner
    participant B as beforeAll Hook
    participant D as dbUtils.start()
    
    T->>B: Start test setup
    B->>D: Invoke start() and await result
    D-->>B: Return MongoMemoryServer instance
    B->>T: Complete setup with mongod instance
Loading
sequenceDiagram
    participant F as Test Function
    participant C as db() Function
    participant M as MongoClient
    
    F->>C: Request database connection
    C->>M: Call MongoClient.connect(uri)
    M-->>C: Return connected client
    C-->>F: Provide connection details (using mongod.instanceInfo)
Loading

Warning

Review ran into problems

🔥 Problems

Errors were encountered while retrieving linked issues.

Errors (1)
  • JIRA integration encountered authorization issues. Please disconnect and reconnect the integration in the CodeRabbit UI.

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8c0a6e5 and 42aa306.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (7)
  • package.json (3 hunks)
  • test/aggregate.test.ts (1 hunks)
  • test/find.test.ts (2 hunks)
  • test/findWithReq.test.ts (1 hunks)
  • test/search.test.ts (1 hunks)
  • test/support/db.ts (2 hunks)
  • test/utils/bsonUrlEncoding.test.ts (3 hunks)
🔇 Additional comments (14)
test/search.test.ts (1)

13-13: Good update to properly await database initialization.

The addition of the await keyword correctly ensures that the MongoDB in-memory server is fully initialized before proceeding with the tests, preventing potential race conditions.

test/findWithReq.test.ts (1)

14-14: Proper async handling added to database initialization.

Adding await for the database start operation ensures tests don't run until the database is ready, which is an important improvement for test reliability.

test/aggregate.test.ts (1)

14-14: Correctly updated async database initialization.

The addition of await ensures proper sequencing of test setup, which is crucial for consistent test behavior across test runs.

test/utils/bsonUrlEncoding.test.ts (3)

1-1: Good update to import ObjectId directly from bson.

This change correctly updates the import source to use the modern BSON module directly rather than going through mongoist, aligning with MongoDB v6+ best practices.


14-14: Proper async handling added to database initialization.

Adding await for the database start operation ensures tests don't run until the database is ready, which is an important improvement for test reliability.


25-25: Correct update to ObjectId instantiation.

Using new ObjectId() instead of the deprecated mongo.ObjectID aligns with the current MongoDB Node.js driver API patterns, increasing future compatibility.

test/find.test.ts (2)

14-14: Good asynchronous handling for database initialization

The change to await dbUtils.start() ensures that the MongoDB memory server is fully initialized before proceeding with tests, which improves reliability and prevents race conditions.


760-760: Modernized MongoDB operation syntax

Replacing remove({}) with deleteMany({}) is the correct approach as it aligns with MongoDB's current best practices. The remove() method is deprecated in newer MongoDB driver versions.

package.json (3)

19-19: Simplified test script

Removing the DRIVER_VERSION=v3 flag simplifies the test script and aligns with the migration to MongoDB driver 6.x, which no longer requires version-specific configuration.


43-43: Updated MongoDB dependencies

Good job updating all MongoDB-related dependencies to their latest major versions. These updates are necessary for MongoDB v7 support:

  • bson: ^6.10.3
  • mongodb: ^6.15.0
  • mongodb-memory-server: ^10.1.4
  • mongoist: ^4.0.1
  • mongoose: ^8.12.2

This aligns perfectly with the PR objectives.

Also applies to: 65-68


55-55: Added Express type definitions

Adding TypeScript type definitions for Express improves type safety and developer experience when working with Express-related code.

test/support/db.ts (3)

5-7: Modernized MongoMemoryServer initialization

The function has been correctly updated to use the async/await pattern with MongoMemoryServer.create(), which is the recommended approach in the latest mongodb-memory-server version. This change ensures compatibility with MongoDB driver 6.x and follows modern JavaScript best practices.


10-10: Simplified client type

Removing the MongoClientV3 type option simplifies the interface and aligns with the move to a single supported MongoDB driver version.


20-23: Streamlined database connection logic

The connection logic has been improved by:

  1. Using Promise.all for parallel execution of connection and dbName retrieval
  2. Using modern MongoClient.connect without version checking
  3. Accessing the database name through the instanceInfo property

These changes make the code more maintainable and compatible with MongoDB driver 6.x.

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

BREAKING CHANGE: Updated to MongoDB driver v6 which requires:
- BSON types must be from version 6.x
- Node.js version compatible with MongoDB 6.x
- Updated connection patterns and BSON handling
- Removed support for deprecated methods

Signed-off-by: Alejandro Dominguez <[email protected]>
@adborroto adborroto force-pushed the adborroto/bump-up-mongodb branch from 94aa7c9 to 42aa306 Compare March 28, 2025 16:10
@@ -16,7 +16,7 @@
"semantic-release": "SEMANTIC_COMMITLINT_SKIP=f4543f643bac890c627d538e6200c5f5a1d45ebc semantic-release",
"test": "npm run test:mongoist && npm run test:native",
"test:mongoist": "DRIVER=mongoist jest --forceExit",
"test:native": "DRIVER=native jest && DRIVER=native DRIVER_VERSION=v3 jest",
Copy link
Contributor Author

@adborroto adborroto Mar 28, 2025

Choose a reason for hiding this comment

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

Remove the support for v3, is just too old

image

@adborroto adborroto requested review from ahmed-anas and a team March 28, 2025 16:12
@adborroto adborroto merged commit 586c018 into master Mar 31, 2025
5 checks passed
@adborroto adborroto deleted the adborroto/bump-up-mongodb branch March 31, 2025 20:13
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.

2 participants