I fetch user Result from database(Mongodb using Mongoose) in Nodejs. Now I want to delete some keys in the user Result. But unable to delete its property. I searched many times but didn't find any solution to delete
Example:-
File1.js Fetched user by mongo query
userModel.findOne(query, projection)
.then(function (result) {
if (result)
return result;
return false
})
The above query fetch the result from the database and the result looks like
user = {
f_name: "Vikas",
l_name: "Kohli",
key1: "abcD",
key2: "dhdhdh"
}
File2.js
user = {
f_name: "Vikas",
l_name: "Kohli",
key1: "abcD",
key2: "dhdhdh"
}
inputuser = "dfdfhdfgy"
Create userkey with using key1 of user result then compare
(_.isEqual(userkey, user.key2)){
//call to next file
}else{
//send response as key not matched
}
Doing some logic, fetch the user's key and then doing some encryption method using key2
Finally compare key2 with userResullt key 2(that I fetched from db) If its ok, then pass to next function
File3.js Expected Output:-
user = {
f_name: "Vikas",
l_name: "Kohli"
}
Current Scenario:-
user = {
f_name: "Vikas",
l_name: "Kohli",
key1: "abcD"
key2: "dhdhdh"
}
Now want to send the response with the user result with deleted key1 and key2 but unable to delete that keys
The delete keyword does not delete inherited properties, but if you delete a prototype property, it will affect all objects inherited from the prototype. (From w3schools, developer.mozilla)
Also found some useful links but none of them working for me. How can I achieve that?
Clarification on the inability of javascript deleting inherited properties.
Why delete operator returns true even if property wasn't deleted from an object