Skip to content

Conversation

@RaschidJFR
Copy link
Contributor

@RaschidJFR RaschidJFR commented Dec 30, 2025

Pull Request

Issue

Closes: #9996

Approach

Added a call to MongoClient.appendMetadata() before calling MongoClient.connect() inside MongoStorageAdapter and GridFSBucketAdapter classes so that medatata is appended from the moment a connection is opened to MongoDB.

Tasks

  • Add tests
  • Add changes to documentation (guides, repository pages, code comments)
  • Add security check
  • Add new Parse Error codes to Parse JS SDK

Summary by CodeRabbit

  • Chores
    • Improve MongoDB client connections by attaching consistent driver metadata (name and version) so the server is identifiable to the driver.
  • Tests
    • Added tests verifying that the driver metadata is included when storage adapters establish MongoDB connections.

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

@parse-github-assistant
Copy link

parse-github-assistant bot commented Dec 30, 2025

🚀 Thanks for opening this pull request!

@coderabbitai
Copy link

coderabbitai bot commented Dec 30, 2025

📝 Walkthrough

Walkthrough

Adds driver metadata (name: "Parse Server", version from package.json) to MongoDB client connections in two storage adapters and adds tests verifying the metadata is propagated to the MongoDB driver.

Changes

Cohort / File(s) Summary
Storage adapters
src/Adapters/Storage/Mongo/MongoStorageAdapter.js, src/Adapters/Files/GridFSBucketAdapter.js
Import package.json, construct driverInfo { name: 'Parse Server', version: pkg.version } and pass it into MongoClient connection options to attach wrapping-library metadata.
Tests
spec/MongoStorageAdapter.spec.js, spec/GridFSBucketStorageAdapter.spec.js
Add "pass metadata to MongoClient" tests that connect adapters and assert the MongoDB client's driverInfo (via client options/internal fields) includes Parse Server name and package version.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant Adapter as Parse Adapter
  participant MongoClient as mongodb.MongoClient
  participant MongoDB as MongoDB Server
  Note over Adapter,MongoClient: Adapter builds connection options\nincluding driverInfo {name, version}
  Adapter->>MongoClient: connect(uri, {...options, driverInfo})
  MongoClient->>MongoDB: handshake with driverInfo metadata
  MongoDB-->>MongoClient: handshake response
  MongoClient-->>Adapter: connected client instance
  Note right of Adapter: Tests inspect client.s.options.driverInfo\n(or internal fields) to verify metadata
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning The implementation uses driverInfo option instead of the appendMetadata() method specified in issue #9996 requirements. Replace the driverInfo option implementation with MongoClient.appendMetadata() calls as specified in the issue and demonstrated by Meteor, Mongoose, and LangChainJS examples.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title 'feat: Add metadata to mongodb client' clearly and concisely describes the main change in the PR.
Description check ✅ Passed The PR description includes the required sections: Issue reference (#9996), Approach explanation, and completed Tasks checklist.
Out of Scope Changes check ✅ Passed All changes are focused on adding MongoDB metadata propagation; no unrelated code modifications are present.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between faf0116 and f4a93ae.

📒 Files selected for processing (2)
  • src/Adapters/Files/GridFSBucketAdapter.js
  • src/Adapters/Storage/Mongo/MongoStorageAdapter.js
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/Adapters/Files/GridFSBucketAdapter.js
  • src/Adapters/Storage/Mongo/MongoStorageAdapter.js

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.

@parseplatformorg
Copy link
Contributor

parseplatformorg commented Dec 30, 2025

Snyk checks have passed. No issues have been found so far.

Status Scanner Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@RaschidJFR RaschidJFR changed the title feat:(Adapters): add metadata to mongodb client feat: add metadata to mongodb client Dec 30, 2025
@parse-github-assistant
Copy link

I will reformat the title to use the proper commit message syntax.

@parse-github-assistant parse-github-assistant bot changed the title feat: add metadata to mongodb client feat: Add metadata to mongodb client Dec 30, 2025
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
src/Adapters/Storage/Mongo/MongoStorageAdapter.js (1)

187-187: Add missing semicolon for consistency.

The closing brace on line 187 is missing a semicolon, which is inconsistent with the rest of the codebase style.

🔎 Suggested fix
     const driverInfo = {
       name: 'Parse Server',
       version: pkg.version,
-    }
+    };
src/Adapters/Files/GridFSBucketAdapter.js (1)

49-56: Add missing semicolon for consistency.

The implementation correctly mirrors the MongoStorageAdapter pattern. However, the closing brace on line 53 is missing a semicolon.

🔎 Suggested fix
       const driverInfo = {
         name: 'Parse Server',
         version: pkg.version,
-      };
+      };
       const mongoclient = new MongoClient(this._databaseURI, this._mongoOptions);
📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 774cc54 and faf0116.

📒 Files selected for processing (4)
  • spec/GridFSBucketStorageAdapter.spec.js
  • spec/MongoStorageAdapter.spec.js
  • src/Adapters/Files/GridFSBucketAdapter.js
  • src/Adapters/Storage/Mongo/MongoStorageAdapter.js
🧰 Additional context used
🧠 Learnings (6)
📓 Common learnings
Learnt from: mtrezza
Repo: parse-community/parse-server PR: 0
File: :0-0
Timestamp: 2025-12-02T08:00:20.138Z
Learning: For Parse Server 9 release (PR #9938 and related), the parse/push-adapter dependency must be upgraded to version >= 8.0.0, not 7.0.0. Version 8.x drops support for Node 18.
Learnt from: mtrezza
Repo: parse-community/parse-server PR: 0
File: :0-0
Timestamp: 2025-11-08T13:46:04.940Z
Learning: When reviewing Parse Server PRs that add new features, always check whether the feature is documented in the README.md file, though for new Parse Server options this is optional rather than required.
📚 Learning: 2025-12-02T08:00:20.138Z
Learnt from: mtrezza
Repo: parse-community/parse-server PR: 0
File: :0-0
Timestamp: 2025-12-02T08:00:20.138Z
Learning: For Parse Server 9 release (PR #9938 and related), the parse/push-adapter dependency must be upgraded to version >= 8.0.0, not 7.0.0. Version 8.x drops support for Node 18.

Applied to files:

  • src/Adapters/Files/GridFSBucketAdapter.js
  • src/Adapters/Storage/Mongo/MongoStorageAdapter.js
📚 Learning: 2025-05-09T09:59:06.289Z
Learnt from: mtrezza
Repo: parse-community/parse-server PR: 9445
File: spec/ParseLiveQuery.spec.js:1340-1375
Timestamp: 2025-05-09T09:59:06.289Z
Learning: Tests in the parse-server repository should use promise-based approaches rather than callback patterns with `done()`. Use a pattern where a Promise is created that resolves when the event occurs, then await that promise.

Applied to files:

  • spec/MongoStorageAdapter.spec.js
  • spec/GridFSBucketStorageAdapter.spec.js
📚 Learning: 2025-11-08T13:46:04.940Z
Learnt from: mtrezza
Repo: parse-community/parse-server PR: 0
File: :0-0
Timestamp: 2025-11-08T13:46:04.940Z
Learning: For new Parse Server options, verify that the option is documented in src/Options/index.js and that npm run definitions has been executed to reflect changes in src/Options/docs.js and src/Options/Definitions.js. README.md documentation is a bonus but not required for new options.

Applied to files:

  • src/Adapters/Storage/Mongo/MongoStorageAdapter.js
📚 Learning: 2025-05-04T20:41:05.147Z
Learnt from: mtrezza
Repo: parse-community/parse-server PR: 9445
File: spec/ParseLiveQuery.spec.js:1312-1338
Timestamp: 2025-05-04T20:41:05.147Z
Learning: New tests in the parse-server repository should use async/await with promise-based patterns rather than callback patterns with `done()`.

Applied to files:

  • spec/GridFSBucketStorageAdapter.spec.js
📚 Learning: 2025-05-09T09:59:06.289Z
Learnt from: mtrezza
Repo: parse-community/parse-server PR: 9445
File: spec/ParseLiveQuery.spec.js:1340-1375
Timestamp: 2025-05-09T09:59:06.289Z
Learning: New tests in the parse-server repository should use async/await with promise-based patterns rather than callback patterns with `done()`. The preferred pattern is to create a Promise that resolves when an expected event occurs, then await that Promise.

Applied to files:

  • spec/GridFSBucketStorageAdapter.spec.js
🧬 Code graph analysis (2)
src/Adapters/Files/GridFSBucketAdapter.js (1)
src/Adapters/Storage/Mongo/MongoStorageAdapter.js (3)
  • driverInfo (184-187)
  • mongoclient (188-188)
  • MongoClient (26-26)
spec/GridFSBucketStorageAdapter.spec.js (1)
src/Adapters/Files/GridFSBucketAdapter.js (1)
  • GridFSBucketAdapter (16-261)
⏰ 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). (10)
  • GitHub Check: Node 20
  • GitHub Check: MongoDB 8, ReplicaSet
  • GitHub Check: Redis Cache
  • GitHub Check: Node 22
  • GitHub Check: MongoDB 7, ReplicaSet
  • GitHub Check: PostgreSQL 17, PostGIS 3.5
  • GitHub Check: PostgreSQL 16, PostGIS 3.5
  • GitHub Check: Benchmarks
  • GitHub Check: PostgreSQL 18, PostGIS 3.6
  • GitHub Check: Docker Build
🔇 Additional comments (3)
spec/GridFSBucketStorageAdapter.spec.js (1)

479-487: LGTM! Test correctly verifies metadata propagation.

The test properly uses async/await and validates that the MongoDB driver receives the correct driverInfo. While accessing _client.s.options relies on MongoDB driver internals, this is currently the most practical way to verify the metadata was applied.

spec/MongoStorageAdapter.spec.js (1)

452-460: LGTM! Metadata validation test is correct.

The test follows async/await best practices and properly verifies the driverInfo metadata. Consistent with the GridFSBucketAdapter test implementation.

src/Adapters/Storage/Mongo/MongoStorageAdapter.js (1)

183-190: appendMetadata API is confirmed available in MongoDB driver 6.20.0.

The appendMetadata() method is supported in mongodb v6.20.0 (introduced in v6.18.0) and the implementation correctly passes the driverInfo object with name and version fields. No changes needed.

coderabbitai[bot]
coderabbitai bot previously approved these changes Dec 30, 2025
@codecov
Copy link

codecov bot commented Dec 30, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.53%. Comparing base (774cc54) to head (f4a93ae).

Additional details and impacted files
@@           Coverage Diff           @@
##            alpha    #9997   +/-   ##
=======================================
  Coverage   92.53%   92.53%           
=======================================
  Files         190      190           
  Lines       15470    15474    +4     
  Branches      176      176           
=======================================
+ Hits        14315    14319    +4     
  Misses       1143     1143           
  Partials       12       12           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@RaschidJFR RaschidJFR force-pushed the feature/mongodb_append_metadata branch from 08d9a9e to f4a93ae Compare December 31, 2025 05:04
@RaschidJFR RaschidJFR marked this pull request as ready for review December 31, 2025 05:24
@mtrezza
Copy link
Member

mtrezza commented Dec 31, 2025

See #9996 (comment)

@mtrezza
Copy link
Member

mtrezza commented Dec 31, 2025

@coderabbitai see the discussion in #9930 and suggest the required changes in this PR to make this an opt-in feature.

@coderabbitai
Copy link

coderabbitai bot commented Dec 31, 2025

Tip

For best results, initiate chat on the files or code changes.

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Fetch PR #9930 details and comments to understand the opt-in discussion
gh pr view 9930 --repo parse-community/parse-server --json title,body,comments --jq '{title, body, comments: [.comments[] | {author: .author.login, body: .body}]}'

Length of output: 22790


@mtrezza Based on the discussion in PR #9930, here are the required changes to make this an opt-in feature:

Implementation Changes Required

1. Add a new Parse Server option

Add a new option in src/Options/index.js to control MongoDB client metadata:

/**
 * Custom metadata to append to MongoDB client connections for identifying Parse Server instances in MongoDB logs.
 * If set, this metadata will be visible in mongos/mongod logs during connection handshakes.
 * This can help with debugging and monitoring in deployments with multiple database clients.
 * Set to a string value like a deployment identifier, server version, or commit hash.
 * Leave undefined (default) to disable this feature and avoid the additional data transfer overhead.
 * @type {string}
 * @default undefined
 */
mongoDBClientMetadata: undefined,

2. Update MongoStorageAdapter

Modify src/Adapters/Storage/Mongo/MongoStorageAdapter.js:

async connect() {
  if (this.connectionPromise) {
    return this.connectionPromise;
  }

  // Remove the pkg import from top of file
  // Only use driverInfo if mongoDBClientMetadata option is set
  const options = { ...this._mongoOptions };
  
  if (this.mongoOptions.mongoDBClientMetadata) {
    options.driverInfo = {
      name: this.mongoOptions.mongoDBClientMetadata,
      version: pkg.version
    };
  }

  this.connectionPromise = MongoClient.connect(encodedUri, options)
    .then(client => {
      // ... rest of the connection logic
    });

  return this.connectionPromise;
}

3. Update GridFSBucketAdapter

Similarly modify src/Adapters/Files/GridFSBucketAdapter.js:

async _connect() {
  if (!this._connectionPromise) {
    const options = { ...this._mongoOptions };
    
    if (this._mongoOptions.mongoDBClientMetadata) {
      options.driverInfo = {
        name: this._mongoOptions.mongoDBClientMetadata,
        version: pkg.version
      };
    }

    this._connectionPromise = MongoClient.connect(this._uri, options).then(client => {
      this._client = client;
      return client.db(this._databaseName);
    });
  }
  return this._connectionPromise;
}

4. Update tests

Modify the tests to verify opt-in behavior:

In spec/MongoStorageAdapter.spec.js:

it('should not pass metadata to MongoClient by default', async () => {
  const adapter = new MongoStorageAdapter({ uri: databaseURI });
  await adapter.connect();
  expect(adapter.client.s.options.driverInfo).toBeUndefined();
});

it('should pass custom metadata to MongoClient when configured', async () => {
  const customMetadata = 'MyParseServer-v1.0.0';
  const adapter = new MongoStorageAdapter({ 
    uri: databaseURI,
    mongoDBClientMetadata: customMetadata
  });
  await adapter.connect();
  expect(adapter.client.s.options.driverInfo.name).toBe(customMetadata);
  expect(adapter.client.s.options.driverInfo.version).toBe(require('../package.json').version);
});

Similar changes in spec/GridFSBucketStorageAdapter.spec.js

5. Run npm definitions

After updating src/Options/index.js, run:

npm run definitions

This will automatically update src/Options/Definitions.js and src/Options/docs.js.

Rationale

This opt-in approach addresses the concerns from PR #9930:

  • Cost: Avoids unnecessary data transfer overhead for the majority of deployments
  • Security: Doesn't expose server version/metadata by default
  • Flexibility: Allows developers to set custom identifiers (deployment name, version, commit hash, etc.)
  • Default behavior: Most Parse Server deployments are the only DB client, making this unnecessary by default

Would you like me to generate a complete code example for any of these changes?


🧠 Learnings used
Learnt from: mtrezza
Repo: parse-community/parse-server PR: 0
File: :0-0
Timestamp: 2025-11-08T13:46:04.940Z
Learning: When reviewing Parse Server PRs that add new features, always check whether the feature is documented in the README.md file, though for new Parse Server options this is optional rather than required.

Learnt from: mtrezza
Repo: parse-community/parse-server PR: 0
File: :0-0
Timestamp: 2025-12-02T06:55:53.808Z
Learning: When reviewing Parse Server PRs that add or modify Parse Server options, always verify that changes are properly reflected in three files: src/Options/index.js (where changes originate), src/Options/Definitions.js, and src/Options/docs.js. The correct workflow is: make changes in index.js first, then run `npm run definitions` to automatically replicate the changes to Definitions.js and docs.js.

Learnt from: mtrezza
Repo: parse-community/parse-server PR: 0
File: :0-0
Timestamp: 2025-11-08T13:46:04.940Z
Learning: For new Parse Server options, verify that the option is documented in src/Options/index.js and that npm run definitions has been executed to reflect changes in src/Options/docs.js and src/Options/Definitions.js. README.md documentation is a bonus but not required for new options.

Learnt from: mtrezza
Repo: parse-community/parse-server PR: 0
File: :0-0
Timestamp: 2025-12-02T08:00:20.138Z
Learning: For Parse Server 9 release (PR #9938 and related), the parse/push-adapter dependency must be upgraded to version >= 8.0.0, not 7.0.0. Version 8.x drops support for Node 18.

Learnt from: mtrezza
Repo: parse-community/parse-server PR: 0
File: :0-0
Timestamp: 2025-11-17T15:02:48.786Z
Learning: For Parse Server PRs, always suggest an Angular commit convention PR title that would make a meaningful changelog entry for developers. Update the PR title suggestion on every commit. The format should be: type(scope): description. Common types include feat, fix, perf, refactor, docs, test, chore. The scope should identify the subsystem (e.g., graphql, rest, push, security). The description should be action-oriented and clearly convey the change's impact to developers.

Learnt from: mtrezza
Repo: parse-community/parse-server PR: 0
File: :0-0
Timestamp: 2025-11-17T15:02:24.824Z
Learning: For Parse Server PRs, always suggest an Angular-style PR title that would make a meaningful changelog entry for developers. Update the PR title suggestion with every new commit to the PR.

Learnt from: EmpiDev
Repo: parse-community/parse-server PR: 9770
File: src/triggers.js:446-454
Timestamp: 2025-08-27T09:08:34.252Z
Learning: When analyzing function signature changes in Parse Server codebase, verify that call sites are actually incorrect before flagging them. Passing tests are a strong indicator that function calls are already properly aligned with new signatures.

Learnt from: EmpiDev
Repo: parse-community/parse-server PR: 9770
File: spec/CloudCode.spec.js:446-469
Timestamp: 2025-08-26T14:06:31.853Z
Learning: In the Parse Server codebase, when handling query objects in maybeRunAfterFindTrigger, objects without a where property that contain options like limit/skip should be treated as query JSON with an empty where clause using the spread pattern { where: {}, ...query }, not nested as { where: query }.

Learnt from: mtrezza
Repo: parse-community/parse-server PR: 0
File: :0-0
Timestamp: 2025-12-02T08:00:08.440Z
Learning: For Parse Server 9 release preparation, the parse/push-adapter dependency should be upgraded to version >= 8.0.0, not 7.x, as version 8.x is required despite dropping Node 18 support (which aligns with Parse Server 9's removal of EOL Node versions).

Learnt from: EmpiDev
Repo: parse-community/parse-server PR: 9770
File: src/triggers.js:467-477
Timestamp: 2025-08-27T12:33:06.237Z
Learning: In the Parse Server codebase, maybeRunAfterFindTrigger is called in production with Parse.Query objects constructed via withJSON(), so the plain object query handling bug only affects tests, not production code paths.

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.

Add metadata for MongoDB

3 participants