Event : The event argument carries the input parameters for the function and is in JSON syntax .
Context : context refers to the object within the function being executed. this refers to the object that the function is executing .
Callback : The third argument, callback , is a function that you can call in non-async handlers to send a response.
These are the three types of arguments that gets passed in a function.
var req = JSON.parse(event.body);
JSON.parse - is used to convert the json string into object .
There are 3 types of variables that can be used in a project .
VAR - used in function
LET - used in Block
CONST - used globally
var user_id = mongoose.Types.ObjectId(req.data._id);
When ever we are adding a user via any kind of forms , the add endpoint gets hit and the MONGO DB generates itself a field named _id .
Now this _id is nothing but the user id which is helpful in identification of the user .
But MONGO DB stores the _id in OBJECT ID fashion .
For this we need convert the _id to Object ID so that Mongo DB can easily differentiate.
Therefore we have used a variable named user_id and where the _id from data is being fetched and converted to objectid and stored in user_id
Then we have connected to database and by users.findbyidandremove (user_id) we have successfully performed the delete operation on postman.
JSON. stringify() :JSON. stringify() method converts a JavaScript object to a JSON string .
Statuscode :200 : The HTTP 200 OK success status response code indicates that the request has succeeded.
Statuscode :500 : HTTP 500 Internal Server Error server error response code indicates that the server encountered an unexpected condition that prevented it from fulfilling the request