🎉 Celebrate with 10% OFF on All Products! Use Code: GFEX10 Or Buy Any 2+ Items for 30% OFF with Code: GFEX30!

Gravity Forms Mongodb Integration Add-on

Updated 13 min read Gravity Forms Files, Storage & Databases
On this page
  1. System requirements
  2. Install and activate
  3. Step 1: Prepare the MongoDB user and the connection string
  4. Step 2: Connect in the add-on settings
  5. Without the extension: the HTTPS endpoint
  6. Step 3: Create a feed
  7. Nested keys and typed values
  8. The _id of the document
  9. Insert or update
  10. Retries, errors and double documents
  11. Send old entries
  12. Security
  13. Troubleshooting
  14. Developer hooks
  15. Frequently asked questions
  16. Can I connect to MongoDB Atlas with a mongodb+srv:// string?
  17. Are the entries still stored in WordPress?
  18. Can documents expire automatically?
  19. Does it work with Change Streams, Atlas Search or aggregation pipelines?
  20. Will a slow or unavailable MongoDB slow down my form?

The Gravity Forms MongoDB Integration Add-on writes every Gravity Forms entry as a document into a collection of your own MongoDB (a server of your own or MongoDB Atlas). You choose the database and the collection, map form fields to document keys (nested keys and typed values are supported), and decide whether a document is inserted or updated. Writes run in the background, so the form never waits for your database, and a database that is down is tried again later without double documents. Version 2.0.0 is a full rebuild: earlier versions only added an entry note and never connected to MongoDB.

System requirements

  • WordPress 5.8 or newer, Gravity Forms 2.5 or newer, PHP 7.4 or newer.
  • Direct connection: the PHP mongodb extension (ext-mongodb: version 1.20 is the last one for PHP 7.4 and 8.0, versions 1.21 and 2.x are for PHP 8.1 and newer). Only the extension is needed; the separate PHP library is not used. If the extension is missing, the add-on shows a notice and the settings page tells you. Ask your host to install it (pecl install mongodb).
  • HTTPS endpoint: no extension needed. Use it when you cannot install the extension (see “Without the extension” below).
  • MongoDB 4.0 or newer, self-hosted or Atlas. The add-on uses the standard insert, update, createIndexes, ping and buildInfo commands.
  • Outbound access from your web server to your MongoDB hosts and port (27017 by default). For Atlas, add the address of your web server to Network Access, IP Access List.

Install and activate

  1. Download the ZIP from My Account, Downloads on your GravityExtra account.
  2. In WordPress go to Plugins, Add New, Upload Plugin, choose the ZIP and activate it. If you run version 1.0.x, install the ZIP over it: WordPress replaces the old plugin, your saved settings and feeds are kept, and the old host, port, user and password become one encrypted connection string automatically.
  3. Go to Forms, Settings, MongoDB Add-On and enter your licence key under Gravity Extra License. Nothing is written until the key is accepted.

New versions appear under Dashboard, Updates like any other plugin.

Step 1: Prepare the MongoDB user and the connection string

Make a database user for the add-on with the readWrite role on the database that receives the documents. That role covers inserts, updates and, for the optional unique index, creating an index. In MongoDB Atlas use Database Access, Add New Database User, then Connect, Drivers to copy the connection string, which looks like this:

mongodb+srv://gf_sync_user:YOUR_PASSWORD@cluster0.abcde.mongodb.net/mydatabase?retryWrites=true&w=majority

A self-hosted server uses mongodb://user:password@host:27017/mydatabase; several hosts of a replica set are separated by commas. Characters such as @ : / ? # in the password must be percent-encoded (for example @ as %40). The database named in the string is the default database of the add-on. Options such as authSource, replicaSet, tls and tlsCAFile are passed on to the driver as they are.

Step 2: Connect in the add-on settings

  1. Open Forms, Settings, MongoDB Add-On.
  2. Keep Connection on Direct connection (PHP mongodb extension).
  3. Paste the Connection string. It is stored encrypted with your site keys and is never shown again; the screen only shows the kind and host without the credentials. Leave the box empty to keep the saved string, or tick Remove the stored connection string.
  4. Default database (optional): the database that feeds write to. Empty means the database named in the connection string; a feed can name another one.
  5. Write concern (optional): Server default, w: 1 or w: majority. Majority waits until most members of a replica set have the document, for at most 10 seconds.
  6. Click Test connection. The add-on connects, sends a ping and reads the server version. You see the MongoDB version, whether the connection is encrypted and the default database. The test uses the string typed on the screen, or the saved one when the box is empty. Nothing is written.
  7. Click Save Settings.

Write while the visitor waits is off by default: the entry is queued and written a moment later by WordPress cron. Turn it on only if you need the document to exist before the confirmation page shows; a slow database then slows that visitor down (the driver waits at most 5 seconds to find a server and 15 seconds for an answer, unless your connection string sets other timeouts).

MongoDB Add-On settings with the connection string, default database, write concern and Test connection
Figure 1: Forms, Settings, MongoDB Add-On: the connection settings.

Without the extension: the HTTPS endpoint

MongoDB switched off its own Atlas Data API on 30 September 2025, so there is no hosted HTTPS service to call any more. If your host cannot install the PHP mongodb extension, you can run a small endpoint of your own that answers the same requests the Data API answered, and the add-on will talk to it. MongoDB’s migration page lists ways to do that, for example an Azure Function made from the template of the MongoDB partners, or a small Express application. Choose HTTPS endpoint (Data API compatible, no extension needed) and fill in:

  • Endpoint address: the base address, which must start with https://. The add-on adds /action/insertOne, /action/updateOne and (for the test) /action/findOne.
  • Key header name and Endpoint key: api-key for an endpoint made like the former Data API, x-functions-key for an Azure Function, or Authorization (the key is then sent as a Bearer token). The key is stored encrypted and never shown again.
  • Data source: sent as dataSource (the cluster name); endpoints that serve one cluster ignore it.

Each request is a POST with a JSON body: dataSource, database, collection and, for an insert, document, for an update filter, update (with $set and $setOnInsert) and upsert. Dates and ObjectIds are sent as MongoDB Extended JSON ({"$date":{"$numberLong":"..."}}, {"$oid":"..."}). The endpoint answers with HTTP 200 and the usual fields (insertedId, matchedCount, modifiedCount, upsertedId); a duplicate _id must come back as an error that contains the MongoDB text E11000 duplicate key error. Through an endpoint the add-on cannot create indexes, so the unique index option is skipped there (make the index in MongoDB), and the write concern setting does not apply. Everything else works the same way, including the retries.

Step 3: Create a feed

  1. Open the form, then Settings, MongoDB Add-On, and click Add New.
  2. Feed Name: any name, for example Workshop signups to MongoDB.
  3. Collection: the collection that gets one document per entry, written exactly as it is in MongoDB (case counts). MongoDB makes the collection when the first document arrives. Database (optional) sends this feed to another database.
  4. Module: Insert document, or Insert or update the document (upsert on a key) (see below).
  5. Document keys: I choose the keys shows the Key Mapping table, where you type the document key and pick a form field, an entry detail (entry ID, form ID, date created, source URL, user ID, payment fields, IP address) or a custom value with merge tags. Build the document from the form fields names the keys after the field labels (or field IDs), turns name and address fields into sub-documents and lets you tick the entry details to add. You can put all the answers inside one sub-document (for example payload).
  6. Empty answers: write null (default), leave the key out, or keep empty text and empty lists.
  7. Enable Condition: tick it to write only the entries that match your rules.

You can add several feeds to one form, and several forms can write to the same collection.

MongoDB feed settings with the Insert or update module and a key
Figure 2: A feed that inserts or updates a document, with the keys built from the form.

Nested keys and typed values

In the Key Mapping table, type the key in the first column, pick the form field in the second column and use the plus button for the next row. A dot makes a nested key: customer.email and customer.name.first write { customer: { email: ..., name: { first: ... } } } (up to 8 levels). End a key with ::type to choose the BSON type: string, int, double, bool, date, objectid, array or json. For example guests::int, signup::date, tags::array, extra::json (a custom value holding JSON text becomes a real sub-document). Without a type the add-on picks one from the field.

Key Mapping table with nested keys and types
Figure 3: The Key Mapping table: nested keys with dots, types after two colons.
Form fieldBSON type without a ::typeWhat is written
Text, email, radio, select, textarea, name and address partsStringThe text as typed.
Number, quantity, total, shippingInt32/Int64 for whole numbers, Double otherwiseA plain number; 1,234.50 and 1.234,50 are read according to the field format. Add ::double to always get a double.
DateDate (UTC)Midnight UTC of the chosen day, read with the format of the field.
TimeStringThe time as typed.
Checkbox, multi select, several filesArray of stringsThe ticked or chosen values.
List fieldArrayOne column: an array of strings. Several columns: an array of sub-documents, one per row.
ConsentBooleantrue when checked.
Entry ID, form ID, user IDIntAs in the entry.
Date created (UTC)DateThe moment of the entry, with the time.
Payment amountNumberAs in the entry.

A value that cannot become the chosen type (a word in an ::int key, a date that does not exist, text that is not JSON) is handled as an empty answer. Empty answers follow the feed setting: null by default. HTML, section, page, captcha and password fields never write anything.

The _id of the document

For an Insert document feed the add-on fixes the _id before the first try, so the same entry can never be inserted twice: either the entry reference text (for example gf3-e127-f9, form 3, entry 127, feed 9) or, if you choose it, an ObjectId that is made once for the entry and kept for every retry. A repeat finds the same _id and changes nothing. If you map a key named _id yourself, it wins; in that case two entries with the same value for it make only one document, so use an update feed when you want the later one to replace the earlier one.

Insert or update

Insert or update the document needs a Key to match: a key of the mapping, such as customer.email. The document that has the same value for that key is updated (the keys of the mapping are set, other keys of the document stay as they are, and sub-documents are merged key by key); when there is none, a new document is inserted with an ObjectId made by MongoDB. The entry must have a single value for the key, otherwise that entry is not written and its note says why. Tick Make sure a unique index exists on the key so that two entries that arrive together can never make two documents with the same key; it needs the user to be allowed to create indexes (the readWrite role is). Without that option, a unique index of your own on the key does the same job.

Retries, errors and double documents

  • A server that cannot be found, a connection that is lost, a busy or changing primary (for example during an Atlas maintenance) and a timeout are tried again after 1 minute, 5 minutes, 30 minutes, 2 hours and 12 hours (six attempts in all). The entry shows the last reason.
  • A wrong user or password, a user without the right to write, a rule of your collection that refuses the document, or a unique index of yours that the document would break is final: the entry gets an error note at once, with the server message and a hint. Other entries are not affected.
  • If the connection is lost while a document is being written, nobody can know whether it was saved. Because the _id is fixed (or the update has a key), the add-on simply tries again and the repeat finds the document that is already there: you get one document, never two.
  • Each entry is written once per feed. Two WordPress cron runs cannot write the same entry at the same time.

Send old entries

Open Forms, Entries, select entries (or all) and choose Send to MongoDB (skip entries already sent) in the bulk actions. Entries are written in the background, 25 at a time. Entries that were already written are skipped, and a message tells you how many were queued and how many skipped. When the form has an update feed, Send to MongoDB again writes the entries of update feeds again, so changed answers reach the documents.

Entry with the note Document inserted into MongoDB collection
Figure 4: Every entry gets a note that says what happened in MongoDB.

Security

  • The connection string and the endpoint key are encrypted at rest with your site keys. If you change the authentication keys in wp-config.php, enter them again. Entry notes, error texts and the test result never contain the credentials.
  • Values are sent as BSON values or JSON data, never glued into a command text. Keys that start with $ are refused.
  • Use an encrypted connection (mongodb+srv:// or tls=true) whenever MongoDB is not on the same server, and give the user only the readWrite role on one database.
  • Deleting an entry in WordPress does not delete its document. Remove it in MongoDB when a person asks to be erased.
  • Client-side field level encryption is not part of this add-on.

Troubleshooting

MessageLikely causeWhat to do
MongoDB error 18Wrong user name or password, or the wrong authSource.Fix the connection string (check the percent-encoding of the password and add authSource=admin if needed) and save. Entries that failed can be sent again from the entry list.
MongoDB error 1003No MongoDB server could be reached in time.Check the host name, that the server runs, and that the address of your web server is in the Atlas IP Access List or the firewall. The add-on retries by itself.
MongoDB error 1002The PHP mongodb extension is not installed.Ask your host to install it, or choose the HTTPS endpoint.
MongoDB error 1001The connection string or the endpoint address is not valid.It must start with mongodb:// or mongodb+srv:// (endpoint: https://).
MongoDB error 13The user may not write to the database.Give the user the readWrite role on the database.
MongoDB error 11000A unique index of yours would be broken by the document.Use an update feed with that key, or change the index.
MongoDB error 121The collection has a validation rule and the document does not follow it.Change the mapping or the rule.
MongoDB error 1007 or 1005The endpoint refused the key, or the address is wrong.Check the key, the header name and the address.
Choose the databaseNo database in the settings, the feed or the connection string.Fill in Default database or the Database field of the feed.

Developer hooks

// Change the document before it is written. Dates and ObjectIds made by the add-on are
// objects of GravityExtra\MongoDB\Special (kind: date or oid). You can add DateTime objects
// (both connections) or MongoDB\BSON values (direct connection).
add_filter( 'gform_mongodb_document_pre_send', function ( $document, $feed, $entry, $form ) {
    $document['meta']['ip_hash'] = hash( 'sha256', (string) $entry['ip'] );
    $document['received_at']      = new DateTimeImmutable( 'now', new DateTimeZone( 'UTC' ) );
    return $document;
}, 10, 4 );

// Run code after a document was written. $inserted_id is the _id (the key value for an update feed);
// $action is inserted, updated, unchanged or exists.
add_action( 'gform_mongodb_post_process', function ( $inserted_id, $entry, $feed, $form, $action ) {
    GFAPI::add_note( $entry['id'], 0, 'MongoDB', 'Document ' . $action . ': ' . $inserted_id );
}, 10, 5 );

// Use another connection class (a class that implements GravityExtra\MongoDB\Db).
add_filter( 'gemo_connection', function ( $db, $cfg ) { return $db; }, 10, 2 );

Frequently asked questions

Can I connect to MongoDB Atlas with a mongodb+srv:// string?

Yes. Paste the string from Atlas into the connection string box. The driver reads the cluster addresses from DNS and encrypts the connection with TLS by default. Add your web server to the Atlas IP Access List.

Are the entries still stored in WordPress?

Yes. Gravity Forms keeps every entry as usual. The add-on writes a copy of each entry as a document into MongoDB, so your reports, dashboards and other applications can read it there.

Can documents expire automatically?

That is a MongoDB feature. Map a key to a date (for example created::date with the source Date created, or build the document from the form with Date created ticked) and create a TTL index on that key in MongoDB (db.collection.createIndex({ created_at: 1 }, { expireAfterSeconds: 2592000 })). The add-on does not create TTL indexes.

Does it work with Change Streams, Atlas Search or aggregation pipelines?

The add-on makes ordinary inserts and updates, so whatever you build on the collection (change streams, Atlas Search indexes, aggregation pipelines) sees the documents like any other. Those features are configured in MongoDB, not in the add-on.

Will a slow or unavailable MongoDB slow down my form?

No, not with the default setting. The visitor’s entry is saved by Gravity Forms and the write to MongoDB happens afterwards in the background, with retries. If you turn on Write while the visitor waits, a slow server delays that visitor by up to the driver timeouts.

Still need help?

Our support team answers tickets every day, usually within a few hours.

0
0
Your Cart
Your cart is emptyReturn to Shop
🔥 FREQUENTLY BOUGHT TOGETHER
Complete Combo & Save 40%!
ITEM IN YOUR CART
Gravity Forms Klaviyo Add-on
$39.00/yr
+
🎁 RECOMMENDED ADD-ON SAVE 40% OFF
Original Price: $39.00/yr
Bundle Special Price: $23.40/yr