Skip to content

Instantly share code, notes, and snippets.

@cadebward
Created November 12, 2015 17:35
Show Gist options
  • Star 10 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save cadebward/c8161e13d7e5270cb7ff to your computer and use it in GitHub Desktop.
Save cadebward/c8161e13d7e5270cb7ff to your computer and use it in GitHub Desktop.
Remove `__v` and `_id` from MongoDB
import mongoose, {Schema} from 'mongoose'
export const ServiceSchema = new Schema({
displayName: {type: String, required: true, unique: true}
})
ServiceSchema.set('toObject', {
transform: function (doc, ret) {
ret.id = ret._id
delete ret._id
delete ret.__v
}
})
export default mongoose.model('Service', ServiceSchema)
// inspired by https://gist.github.com/fiveisprime/9749782
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment