Launch Week Day 5: Introducing Reachability for PHP.Learn More
Socket
Book a DemoSign in
Socket

gatsby-source-mongodb

Package Overview
Dependencies
Maintainers
1
Versions
372
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gatsby-source-mongodb - npm Package Compare versions

Comparing version
1.5.1
to
1.5.2
+32
mapping.js
"use strict";
var _defineProperty2 = require("babel-runtime/helpers/defineProperty");
var _defineProperty3 = _interopRequireDefault(_defineProperty2);
var _stringify = require("babel-runtime/core-js/json/stringify");
var _stringify2 = _interopRequireDefault(_stringify);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
module.export = function (node, key, text, createNode) {
var _mappingNode;
var str = _.isString(text) ? text : " ";
var id = "" + node.id + key + "MappingNode";
var mappingNode = (_mappingNode = {
id: id,
parent: node.id
}, (0, _defineProperty3.default)(_mappingNode, key, str), (0, _defineProperty3.default)(_mappingNode, "children", []), (0, _defineProperty3.default)(_mappingNode, "internal", {
type: _.camelCase(node.internal.type + " " + key + " MappingNode"),
mediaType: "text/x-markdown",
content: str,
contentDigest: crypto.createHash("md5").update((0, _stringify2.default)(str)).digest("hex")
}), _mappingNode);
node.children = node.children.concat([mappingNode.id]);
createNode(mappingNode);
return mappingNode;
};
+17
-7

@@ -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"
}
}
+35
-23
# 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
}
}
}
}
}
```