Skip to content

Instantly share code, notes, and snippets.

@themegabyte
Created May 29, 2022 09:43
Show Gist options
  • Select an option

  • Save themegabyte/01ede2b36e5358ea046cf9ad2bf5d58f to your computer and use it in GitHub Desktop.

Select an option

Save themegabyte/01ede2b36e5358ea046cf9ad2bf5d58f to your computer and use it in GitHub Desktop.
Small function to describe mongoose schema.
const describeSchema = (obj) => {
let describeSchema = {};
for (const key of Object.keys(obj.schema.paths)) {
describeSchema[key] = obj.schema.paths[key].instance;
}
return describeSchema;
};
module.exports = describeSchema;
// Usage:
// const describeSchema = require("./describeSchema");
// describeSchema(Mongoose.Model())
// Mongoose.Model() will be your defined mongoose model.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment