Skip to content

Instantly share code, notes, and snippets.

@funador
Created February 17, 2019 16:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save funador/98e524778dd92b1141255c8aadb94e1d to your computer and use it in GitHub Desktop.
Save funador/98e524778dd92b1141255c8aadb94e1d to your computer and use it in GitHub Desktop.
const mongoose = require('mongoose')
const Schema = mongoose.Schema
const { providers } = require('../config')
//
const providerFields = providers.reduce((obj, provider) => {
obj[provider] = {
name: {
type: String
},
photo: {
type: String
}
}
return obj
}, {})
//
const fields = {
email: {
type: String,
unique: true
},
...providerFields
}
// One nice, clean line to create the Schema.
const userSchema = new Schema(fields)
module.exports = mongoose.model('User', userSchema)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment