Registry / database / gatsby-source-mongodb

gatsby-source-mongodb

JSON →
library5.16.0jsnpmunverified

Gatsby source plugin for pulling data from MongoDB collections into the Gatsby data layer. Current stable version 5.16.0 supports Gatsby 5 and Node >=18.0.0 <26. It connects to MongoDB (local, Atlas, or custom) and ingests documents as Gatsby nodes. Supports multiple collections, custom queries, type prefixing, and field mapping for transformer plugins (e.g., markdown to HTML). Differentiators include built-in compatibility with MongoDB Atlas, flexible authentication, and options for preserving ObjectIDs. Release cadence follows Gatsby's major releases.

npm install gatsby-source-mongodb
INSTALL
IMPORT
SIG · GATSBY-SOURCE-MONG
G
gatsby-source-mongodb
databasejavascriptv5.16.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

gatsby-source-mongodb
module.exports = { plugins: [{ resolve: `gatsby-source-mongodb`, options: { ... } }] }
const gatsbySourceMongodb = require('gatsby-source-mongodb')
Used as a Gatsby plugin in gatsby-config.js via resolve string, not imported directly.

Configures the plugin to source MongoDB data from a local instance using environment variables for authentication.

// gatsby-config.js module.exports = { plugins: [ { resolve: `gatsby-source-mongodb`, options: { dbName: `local`, collection: `documents`, server: { address: `127.0.0.1`, port: 27017 }, auth: { user: process.env.MONGO_USER ?? '', password: process.env.MONGO_PASS ?? '' }, }, }, ], }
Debug
Known issues
deprecatedThe `useNewUrlParser` and `useUnifiedTopology` clientOptions defaults are deprecated in newer MongoDB driver versions. They default to true but will be removed.
fix
Set `clientOptions: { useNewUrlParser: false, useUnifiedTopology: false }` or a valid driver option.
affects: >=5.0.0
gotchaWhen using connectionString, the `dbName` option must still be provided explicitly.
fix
Include `dbName` in options even when using connectionString.
affects: *
gotchaThe `preserveObjectIds` option must be a Boolean `true` string or boolean, not 'true' as a string.
fix
Use `preserveObjectIds: true` (Boolean, not string).
affects: *
Errors
Common errors & fixes
Error: Cannot find module 'gatsby-source-mongodb'
Plugin not installed or not in node_modules.
fix
Run `npm install gatsby-source-mongodb`
MongoNetworkError: failed to connect to server [localhost:27017] on first connect [MongoNetworkError: connect ECONNREFUSED 127.0.0.1:27017]
MongoDB server is not running or unreachable.
fix
Start MongoDB service or check connection options.
Upgrade
Version history
5.16.0latest on npm
Audit
Dependencies
gatsbyrequiredpeer dependency for Gatsby 5
Agent activity
4 hits · last 30 days
node
4
Resources
gatsby-source-mongodb — npm install gatsby-source-mongodb · libregistry