I am beginner in NodeJS and MongoDB, and while learning from some online resources I had created mongoose schema as:
const mongoose = require('mongoose')
const blogSchema = mongoose.Schema({
title: String,
author: String,
url: String,
likes: Number,
})
blogSchema.set('toJSON', {
transform: (document, returnedObject) => {
returnedObject.id = returnedObject._id.toString()
delete returnedObject._id
delete returnedObject.__v
}
})
But eslint is keep giving me errors:
- for
returnedObject.id,delete returnedObject._idanddelete returnedObject.__v- Assignment to property of function parameter 'returnedObject'.eslint(no-param-reassign) - for
returnedObject._idandreturnedObject.__v- Unexpected dangling '_' in '_id'.eslint(no-underscore-dangle)
What is the correct way in which I can remove the _id and __v fields and re-assign the _id to id for returnedObject?
I am using airbnb-base eslint configuration (devDependencies from package.json):
"eslint": "^6.8.0",
"eslint-config-airbnb-base": "^14.0.0",
"eslint-plugin-import": "^2.20.1",
