Skip to content

Instantly share code, notes, and snippets.

@cadebward
Created November 12, 2015 17:35
Show Gist options
  • 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