Created
May 29, 2022 09:43
-
-
Save themegabyte/01ede2b36e5358ea046cf9ad2bf5d58f to your computer and use it in GitHub Desktop.
Small function to describe mongoose schema.
This file contains hidden or 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
| 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