Skip to content

Instantly share code, notes, and snippets.

View cjthompson's full-sized avatar

Chris Thompson cjthompson

  • Osiris Development
  • Colorado, USA
View GitHub Profile
@cjthompson
cjthompson / findschema.js
Last active September 28, 2021 20:05
Find all possible fields and their types from a MongoDB collection
var obj = {};
function reduce(accum, doc) {
for (var key in doc) {
if (doc.hasOwnProperty(key) && typeof doc[key] !== 'function') {
const type = typeof doc[key]
if (type === 'object') {
const aKey = (accum[key] && typeof accum[key] === 'string') ? key + '_obj' : key
accum[aKey] = accum[aKey] ? accum[aKey] : {}
reduce(accum[aKey], doc[key])