← MongoDB

New Document from MongoDB API

Pipedream makes it easy to connect APIs for MongoDB and 1000+ other apps remarkably fast.

Trigger workflow on
New Document from the MongoDB API
Next, do this
Connect to 1000+ APIs using code and no-code building blocks
No credit card required
Into to Pipedream
Watch us build a workflow
Watch us build a workflow
7 min
Watch now ➜
Trusted by 250,000+ developers from startups to Fortune 500 companies:
Trusted by 250,000+ developers from startups to Fortune 500 companies

Developers Pipedream

Getting Started

Trigger a workflow on New Document with MongoDB API. When you configure and deploy the workflow, it will run on Pipedream's servers 24x7 for free.

  1. Configure the New Document trigger
    1. Connect your MongoDB account
    2. Configure Polling Interval
    3. Select a Database
    4. Select a Collection
  2. Add steps to connect to 1000+ APIs using code and no-code building blocks
  3. Deploy the workflow
  4. Send a test event to validate your setup
  5. Turn on the trigger

Integrations

Send Message with Discord Webhook API on New Document from MongoDB API
MongoDB + Discord Webhook
 
Try it
Add Multiple Rows with Google Sheets API on New Document from MongoDB API
MongoDB + Google Sheets
 
Try it
Get Film with SWAPI - Star Wars API on New Document from MongoDB API
MongoDB + SWAPI - Star Wars
 
Try it
Create Multiple Records with Airtable API on New Document from MongoDB API
MongoDB + Airtable
 
Try it
Send any HTTP Request with HTTP / Webhook API on New Document from MongoDB API
MongoDB + HTTP / Webhook
 
Try it

Details

This is a pre-built, open source component from Pipedream's GitHub repo. The component is developed by Pipedream and the community, and verified and maintained by Pipedream.

To contribute an update to an existing component or create a new component, create a PR on GitHub. If you're new to Pipedream component development, you can start with quickstarts for trigger span and action development, and then review the component API reference.

New Document on MongoDB
Description:Emit new an event when a new document is added to a collection
Version:0.0.4
Key:mongodb-new-document

Code

import common from "../common/base.mjs";

export default {
  ...common,
  key: "mongodb-new-document",
  name: "New Document",
  description: "Emit new an event when a new document is added to a collection",
  version: "0.0.4",
  type: "source",
  dedupe: "unique",
  props: {
    ...common.props,
    database: {
      propDefinition: [
        common.props.mongodb,
        "database",
      ],
    },
    collection: {
      propDefinition: [
        common.props.mongodb,
        "collection",
        (c) => ({
          database: c.database,
        }),
      ],
    },
  },
  methods: {
    ...common.methods,
    _getDocumentIds() {
      return this.db.get("documentIds");
    },
    _setDocumentIds(documentIds) {
      this.db.set("documentIds", documentIds);
    },
    isRelevant(id, documentIds) {
      return !documentIds.includes(id);
    },
    async processEvent(client, ts) {
      const documentIds = this._getDocumentIds() || [];
      const collection = this.mongodb.getCollection(client, this.database, this.collection);
      const documents = await this.mongodb.listDocuments(collection);
      for (const doc of documents) {
        const id = JSON.stringify(doc._id);
        if (!this.isRelevant(id, documentIds)) {
          continue;
        }
        documentIds.push(id);
        this.emitEvent(doc, ts);
      }
      this._setDocumentIds(documentIds);
    },
    generateMeta({ _id: id }, ts) {
      return {
        id,
        summary: `New Document ID ${JSON.stringify(id)}`,
        ts,
      };
    },
  },
};

Configuration

This component may be configured based on the props defined in the component code. Pipedream automatically prompts for input values in the UI and CLI.
LabelPropTypeDescription
MongoDBmongodbappThis component uses the MongoDB app.
N/Adb$.service.dbThis component uses $.service.db to maintain state between component invocations.
Polling Intervaltimer$.interface.timer

Pipedream will poll the API on this schedule

DatabasedatabasestringSelect a value from the drop down menu.
CollectioncollectionstringSelect a value from the drop down menu.

Authentication

MongoDB uses API keys for authentication. When you connect your MongoDB account, Pipedream securely stores the keys so you can easily authenticate to MongoDB APIs in both code and no-code steps.

Before you connect to your Mongo database from Pipedream, please make sure your database is accessible from the public internet. You may need to add a firewall rule allowing connections from 0.0.0.0/0.

Then, enter the details of your Mongo host / database below.

About MongoDB

The global cloud database service for modern applications

More Ways to Use MongoDB

Triggers

New Collection from the MongoDB API

Emit new an event when a new collection is added to a database

 
Try it
New Database from the MongoDB API

Emit new an event when a new database is added

 
Try it
New Field in Document from the MongoDB API

Emit new an event when a new field is added to a document

 
Try it

Actions

Create New Document with the MongoDB API

Create a new document in a collection of your choice. See the docs here

 
Try it
Delete a Document with the MongoDB API

Delete a single document by ID. See the docs here

 
Try it
Find Document by Id with the MongoDB API

Retrieves a single document by ID. See the docs here

 
Try it
Search Documents with the MongoDB API

Search for specific documents or return all documents. See the docs here

 
Try it
Update a Document with the MongoDB API

Updates a single document by ID. See the docs here

 
Try it