This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* MongoDB JSON Document Recursive Flat | |
* @param {Object|Array} document MongoDB JSON Document | |
* @param {string|undefined} prefixKey used by recursivity to prefix deeper keys with parent keys | |
*/ | |
const flat = (document, prefixKey = undefined) => { | |
const keys = Object.keys(document) | |
keys.forEach(key => { | |
const newKey = prefixKey ? `${prefixKey}_${key}` : key |