Replies: 1 comment 2 replies
-
So what is the question here? Is the issue just that passing an empty string |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I am having extra work to do on the front end because of missing built-in features which should be supported in Mongoose by default.
Request [1]: Either allow all the fields to accept empty strings as a signal to reset the field to empty, or disallow it completely.
Take this example:
I have the following schema:
And on the web front-end, I have the following inputs in an Update User Form (used to update a user):

click here to copy the code 🗒
I want to support the following features:
[] All the fields are optional to be filled.
[] If the field is empty, this means that the user wants to reset the field to empty,
(ex: name: "Jamaal" ---> name: "")
Now, after testing that, the following happens:
Test 1:
Form values:
JSON:
Result:
as expected. the user document has been updated to hold the values in the JSON object.
Test 2:
Form values:
JSON:
Result:
The user document's name field has been updated to become an empty string in the database.
Test 3:
Form values:
JSON:
Result:
The user document's name and age fields have been updated to become empty strings in the database.
Test 4:
Form values:
JSON:
Result:
Now, If I had to fix this problem and allow removing the room field, I would do that on the front-end as follows:
Request [2]: Prevent allowing the Schema types String & Number (idk, and the others?) to accept
null
as a value.Take the following example:
I have the following schema:
and I have the following express routes
Let's pretend that I'm a pro admin who likes to write his blog posts using postman instead of the front-end webpage and I wrote the following in the body of the PATCH request:
And lets say that on the front-end, the code which is used to view the post looks as follows:
In this example, the admin used Postman to perform an XSS attack without noticing, and now the front-end is having problems rendering the blog post, because it's of type null and
.capitalize()
is not a function on null values, it can only be used on strings.This means that we need to find a better way to signal that we want to reset this field to empty from the front end.
Beta Was this translation helpful? Give feedback.
All reactions