Skip to content

Instantly share code, notes, and snippets.

@koolamusic
Forked from cadebward/service.js
Created October 17, 2020 19:35
Show Gist options
  • Save koolamusic/abf215990d77b6b6e85abe931a00b47f to your computer and use it in GitHub Desktop.
Save koolamusic/abf215990d77b6b6e85abe931a00b47f 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