mongo_express's People
mongo_express's Issues
Possibly unsetting already set fields to undefined
mongo_express/routes/TeacherRoute.js
Lines 77 to 89 in 9524a98
Same issue as #1
Possibly unsetting already set fields to undefined
mongo_express/routes/StudentRoute.js
Lines 77 to 86 in 9524a98
In the following code for updating a student, the update argument which is an object could possibly be unsetting an already set field to undefined. Consider an instance where req.body.gender
does not exist in the request body but the student already has a gender set, going by your code the student's gender
field will be set to undefined because it does not exist in the request body. A better way to write the update argument is by simply sending the request body as the update argument. E.g
const updatedStudent = await StudentModel.findOneAndUpdate(
{ student_id: req.params.student_id },
req.body,
{ new: true }
);
By doing that you're only sending the fields that are present in the request body as updates without tampering with fields that have already been set but may not exist in the request body. So in the instance where req.body
is {"first_name": "Frank", "last_name": "Sinatra"}
only the first_name
and last_name
fields will be sent as update arguments.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.