Skip to content

Commit

Permalink
fix(gatsby-source-mongodb): work with _id types that are not O… (#16331)
Browse files Browse the repository at this point in the history
  • Loading branch information
senorpedro authored and sidharthachatterjee committed Aug 8, 2019
1 parent 37c7389 commit d226fd5
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion packages/gatsby-source-mongodb/src/gatsby-node.js
Expand Up @@ -66,6 +66,10 @@ exports.sourceNodes = (
})
}

function idToString(id) {
return id.hasOwnProperty(`toHexString`) ? id.toHexString() : String(id)
}

function createNodes(
db,
pluginOptions,
Expand All @@ -87,7 +91,7 @@ function createNodes(
}

documents.forEach(({ _id, ...item }) => {
const id = _id.toHexString()
const id = idToString(_id)

// only call recursive function to preserve relations represented by objectids if pluginoption set.
if (preserveObjectIds) {
Expand Down

0 comments on commit d226fd5

Please sign in to comment.