-
-
Save shalaby/bf53d2bc2c57ecd6fe3d7775b952540d to your computer and use it in GitHub Desktop.
Remove `__v` and `_id` from MongoDB
This file contains 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
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