UNPKG

@360-l/mongo-bulk-data-migration

Version:
22 lines (21 loc) 916 B
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.flattenDocument = flattenDocument; const lodash_1 = __importDefault(require("lodash")); function flattenDocument(obj) { const outputDocument = {}; return Object.entries(obj).reduce((output, [key, value]) => { const isPlainObject = lodash_1.default.isPlainObject(value) || Array.isArray(value); if (!isPlainObject || lodash_1.default.isEmpty(value)) { output[key] = value; return output; } return Object.entries(flattenDocument(value)).reduce((deepOutput, [flattenKey, flattenValue]) => { deepOutput[`${key}.${flattenKey}`] = flattenValue; return deepOutput; }, output); }, outputDocument); }