Skip to content

MongoDB - update to new-document source #16820

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

Conversation

michelle0927
Copy link
Collaborator

@michelle0927 michelle0927 commented May 23, 2025

Resolves #16805

It looks like it's only not emitting events if the "Timestamp Field" entered isn't of type Timestamp, so I added the option to use a timestamp field of type Integer.

Summary by CodeRabbit

  • New Features
    • Added support for integer-based timestamp fields alongside MongoDB Timestamp objects.
    • Introduced an option to specify the timestamp field type for better flexibility.
  • Bug Fixes
    • Enhanced document querying and timestamp handling based on the selected timestamp field type.

Copy link

vercel bot commented May 23, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

3 Skipped Deployments
Name Status Preview Comments Updated (UTC)
docs-v2 ⬜️ Ignored (Inspect) Visit Preview May 23, 2025 8:13pm
pipedream-docs ⬜️ Ignored (Inspect) May 23, 2025 8:13pm
pipedream-docs-redirect-do-not-edit ⬜️ Ignored (Inspect) May 23, 2025 8:13pm

Copy link
Contributor

coderabbitai bot commented May 23, 2025

"""

Walkthrough

The changes introduce support for integer-based timestamp fields in the MongoDB "New Document" trigger component. A new property allows users to specify the timestamp field type, and the logic for extracting and querying timestamps is updated accordingly. The package version is incremented to reflect these enhancements.

Changes

File(s) Change Summary
components/mongodb/package.json Bumped package version from 0.1.2 to 0.1.3.
components/mongodb/sources/new-document/new-document.mjs Added timestampFieldType property, updated timestamp extraction and query logic for integers.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant MongoDBTrigger
    participant MongoDB

    User->>MongoDBTrigger: Configure trigger (choose timestampFieldType)
    MongoDBTrigger->>MongoDB: Query for new documents using timestampField and type
    MongoDB-->>MongoDBTrigger: Return matching documents
    MongoDBTrigger->>User: Emit new document events
Loading

Assessment against linked issues

Objective Addressed Explanation
Fix MongoDB New Document trigger not emitting events due to timestamp query issue (#16805)

Possibly related PRs

Poem

In the warren where data flows free,
MongoDB triggers now hop with glee!
Integer or Timestamp, both are just right—
New docs detected, day or night.
With version bumped and bugs now gone,
This rabbit cheers, "Hop on, hop on!"
🐇✨
"""

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

components/mongodb/sources/new-document/new-document.mjs

Oops! Something went wrong! :(

ESLint: 8.57.1

Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'jsonc-eslint-parser' imported from /eslint.config.mjs
at Object.getPackageJSONURL (node:internal/modules/package_json_reader:255:9)
at packageResolve (node:internal/modules/esm/resolve:767:81)
at moduleResolve (node:internal/modules/esm/resolve:853:18)
at defaultResolve (node:internal/modules/esm/resolve:983:11)
at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:799:12)
at #cachedDefaultResolve (node:internal/modules/esm/loader:723:25)
at ModuleLoader.resolve (node:internal/modules/esm/loader:706:38)
at ModuleLoader.getModuleJobForImport (node:internal/modules/esm/loader:307:38)
at #link (node:internal/modules/esm/module_job:163:49)

Note

⚡️ AI Code Reviews for VS Code, Cursor, Windsurf

CodeRabbit now has a plugin for VS Code, Cursor and Windsurf. This brings AI code reviews directly in the code editor. Each commit is reviewed immediately, finding bugs before the PR is raised. Seamless context handoff to your AI code agent ensures that you can easily incorporate review feedback.
Learn more here.


📜 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 956123a and 9e3e650.

📒 Files selected for processing (1)
  • components/mongodb/sources/new-document/new-document.mjs (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • components/mongodb/sources/new-document/new-document.mjs
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Verify TypeScript components
  • GitHub Check: Publish TypeScript components
  • GitHub Check: Lint Code Base
✨ 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
🪧 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @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.

Copy link
Contributor

@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: 1

🧹 Nitpick comments (1)
components/mongodb/sources/new-document/new-document.mjs (1)

59-72: Consider adding type validation for the selected timestamp field type.

While the logic correctly handles both timestamp types, there's no validation to ensure the actual field values match the selected timestampFieldType. This could lead to runtime errors if users misconfigure the field type.

Consider adding validation in the getTs method:

 getTs(doc) {
   const tsValue = doc[this.timestampField];
   if (this.timestampFieldType === "Integer") {
+    if (typeof tsValue !== "number" && !Number.isInteger(Number(tsValue))) {
+      console.warn(`Expected integer timestamp but got ${typeof tsValue}: ${tsValue}`);
+    }
     return tsValue;
   }
   // ... rest of the method
 }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between cd1cd42 and 956123a.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (2)
  • components/mongodb/package.json (1 hunks)
  • components/mongodb/sources/new-document/new-document.mjs (4 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: Verify TypeScript components
  • GitHub Check: pnpm publish
  • GitHub Check: Publish TypeScript components
  • GitHub Check: Lint Code Base
🔇 Additional comments (5)
components/mongodb/package.json (1)

3-3: LGTM! Appropriate version bump for new functionality.

The version increment from 0.1.2 to 0.1.3 correctly reflects the addition of integer timestamp field support in the new-document source.

components/mongodb/sources/new-document/new-document.mjs (4)

9-9: LGTM! Component version bump aligns with package version.

The version increment is consistent with the package.json changes and reflects the new integer timestamp support.


32-33: Good update to reflect expanded timestamp type support.

Removing the Timestamp type requirement from the description accurately reflects that the field now supports both Timestamp and Integer types.


61-63: LGTM! Clean implementation for integer timestamp handling.

The early return for integer types correctly bypasses the string/JSON parsing logic and returns the raw integer value as expected.


92-94:

❓ Verification inconclusive

Verify query compatibility with MongoDB integer comparisons.

The conditional query logic correctly handles both timestamp types, but ensure that MongoDB can properly compare integer values in the $gt operation when timestampFieldType is "Integer".

Run the following script to verify MongoDB integer comparison behavior:


🏁 Script executed:

#!/bin/bash
# Description: Search for MongoDB query patterns and integer comparison usage
# Expected: Find examples of integer field comparisons in MongoDB queries

# Search for similar MongoDB query patterns with integer comparisons
rg -A 5 -B 5 '\$gt.*[0-9]+' --type js

Length of output: 39


Confirm BSON integer comparisons in $gt query

We didn’t find any existing examples of numeric $gt comparisons in the codebase. When timestampFieldType === "Integer", make sure that lastTs is sent as a BSON integer (e.g. Int32 or Long) rather than the default BSON double—otherwise your integer‐typed timestamp field may not compare as expected.

• File: components/mongodb/sources/new-document/new-document.mjs
Lines 92–94:

  $gt: this.timestampFieldType === "Integer"
    ? lastTs          // ensure this is wrapped as Int32/Long
    : this.convertToTimestamp(lastTs),

Copy link
Collaborator

@jcortes jcortes left a comment

Choose a reason for hiding this comment

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

Hi @michelle0927 lgtm! Ready for QA!

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] MongoDB trigger not emitting events
2 participants