gatsby-source-mongodb
Advanced tools
Comparing version 1.5.1 to 1.5.2
@@ -16,3 +16,4 @@ "use strict"; | ||
ObjectID = require("mongodb").ObjectID, | ||
crypto = require("crypto"); | ||
crypto = require("crypto"), | ||
_ = require("lodash"); | ||
@@ -59,8 +60,10 @@ exports.sourceNodes = function (_ref, pluginOptions, done) { | ||
} else { | ||
createNode((0, _extends3.default)({}, item, { | ||
id: "" + item._id, | ||
parent: item.parent || "__" + collectionName + "__", | ||
children: item.children || [], | ||
var id = item._id.toString(); | ||
delete item._id; | ||
var node = (0, _extends3.default)({}, item, { | ||
id: "" + id, | ||
parent: "__" + collectionName + "__", | ||
children: [], | ||
internal: { | ||
mediaType: "application/json", | ||
type: "mongodb" + caps(dbName) + caps(collectionName), | ||
@@ -70,3 +73,10 @@ content: (0, _stringify2.default)(item), | ||
} | ||
})); | ||
/* if (pluginOptions.map) { | ||
// We need to map certain fields to a contenttype. | ||
var keys = Object.keys(pluginOptions.map).forEach(mediaItemFieldKey => { | ||
createMappingChildNodes(node, mediaItemFieldKey, item[mediaItemFieldKey], createNode)); | ||
delete item[mediaItemFieldKey]; | ||
}); | ||
} */ | ||
});createNode(node); | ||
} | ||
@@ -73,0 +83,0 @@ }); |
{ | ||
"name": "gatsby-source-mongodb", | ||
"version": "1.5.1", | ||
"version": "1.5.2", | ||
"description": "Stub description for gatsby-source-mongodb", | ||
@@ -19,4 +19,5 @@ "main": "index.js", | ||
"dependencies": { | ||
"lodash": "^4.17.4", | ||
"mongodb": "^2.2.30" | ||
} | ||
} |
# gatsby-source-mongodb | ||
Source plugin for pulling data into [Gatsby](https://github.com/gatsbyjs) from mongoDB collections. | ||
Source plugin for pulling data into [Gatsby](https://github.com/gatsbyjs) from MongoDB collections. | ||
## 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 | ||
This plugin will pull all documents from all collections on the MongoDB server. | ||
## Plugin options | ||
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. | ||
* **dbName**: indicates the database name that you want to use | ||
* **collection**: the collection name within Mongodb | ||
* **server**: contains the server info, with sub properties address and port | ||
ex. server: { address: `ds143532.mlab.com`, port: 43532 }, | ||
* **auth**: the authentication data to login a Mongodb collection, with sub properties user and password. | ||
ex. auth: { user: `admin`, password: `12345` } | ||
### TODO WIP | ||
map: with this option you can map a field to a content type, it is an array | ||
ex. map: {description: `text\x-markdown`} | ||
## How to query : GraphQL | ||
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. | ||
```graphql | ||
query PageQuery { | ||
allMongoDbWebsites { | ||
edges { | ||
node { | ||
id | ||
url | ||
name | ||
allMongoDbDocField { | ||
edges { | ||
node { | ||
id | ||
url | ||
name | ||
} | ||
} | ||
} | ||
} | ||
} | ||
``` |
6457
6
94
52
2
+ Addedlodash@^4.17.4
+ Addedlodash@4.17.21(transitive)