Skip to content

Commit

Permalink
Tweak mongodb readme + add it to plugins list
Browse files Browse the repository at this point in the history
  • Loading branch information
KyleAMathews committed Jul 27, 2017
1 parent d94e042 commit d40b9f4
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 25 deletions.
3 changes: 2 additions & 1 deletion docs/docs/plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ you can place the files in a `src` subfolder and build them to the plugin folder
* [gatsby-source-drupal](/packages/gatsby-source-drupal/)
* [gatsby-source-filesystem](/packages/gatsby-source-filesystem/)
* [gatsby-source-hacker-news](/packages/gatsby-source-hacker-news/)
* [gatsby-source-WordPress](/packages/gatsby-source-wordpress/)
* [gatsby-source-mongodb](/packages/gatsby-source-mongodb/)
* [gatsby-source-wordpress](/packages/gatsby-source-wordpress/)
* [gatsby-transformer-documentationjs](/packages/gatsby-transformer-documentationjs/)
* [gatsby-transformer-javascript-static-exports](/packages/gatsby-transformer-javascript-static-exports/)
* [gatsby-transformer-json](/packages/gatsby-transformer-json/)
Expand Down
49 changes: 26 additions & 23 deletions packages/gatsby-source-mongodb/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,38 @@

Source plugin for pulling data into [Gatsby](https://github.com/gatsbyjs) from mongoDB collections.

## how to use
## How to use

```javascript
// In your gatsby-config.js
plugins: [
/*
* Gatsby's data processing layer begins with “source”
* plugins. Here the site sources its data from mongoDB collection documents.
*/
{
resolve: `gatsby-source-mongodb`,
options: { dbName: `local`, collection: `documents` },
}
],
plugins: [
/*
* Gatsby's data processing layer begins with “source”
* plugins. Here the site sources its data from mongoDB collection documents.
*/
{
resolve: `gatsby-source-mongodb`,
options: { dbName: `local`, collection: `documents` },
}
]
```
## How to query : GraphQL
## How to query

Find below a global pageQuery to query all mongoDB document nodes.
All the documents in mongodb of a certain collection will be pulled into gatsby.
This plugin will pull all documents from all collections on the MongoDB server.

``` graphql
Each collection will be created as a different "node" type. For example
if your db had a collection named "Websites" with documents with url & name fields. You could query it like the following.

```graphql
query PageQuery {
allMongoDbDocField {
edges {
node {
id
url
name
}
allMongoDbWebsites {
edges {
node {
id
url
name
}
}
}
```
}
```
1 change: 0 additions & 1 deletion packages/gatsby-source-mongodb/src/gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ exports.sourceNodes = (
}

function createNodes(db, pluginOptions, dbName, createNode, done) {
console.log(`create nodes with new api ...`)
let collectionName = pluginOptions.collection || `documents`
let collection = db.collection(collectionName)
let cursor = collection.find()
Expand Down

0 comments on commit d40b9f4

Please sign in to comment.