Skip to content
This repository has been archived by the owner on Sep 29, 2020. It is now read-only.

Added User Registration #23

Merged
merged 3 commits into from Jul 22, 2018
Merged

Conversation

IamRaviTejaG-zz
Copy link
Contributor

Fixes #10.

@IamRaviTejaG-zz
Copy link
Contributor Author

@sakshamsaxena @sr6033 Please review. 😄

@IamRaviTejaG-zz
Copy link
Contributor Author

@sakshamsaxena @sr6033 Please review the PR.

@sakshamsaxena
Copy link
Owner

User Schema already exists, I'd recommend using that. I'll review it soon

@IamRaviTejaG-zz
Copy link
Contributor Author

@sakshamsaxena Updated the code accordingly. Please review and suggest changes, if any.

_id: {
type: ObjectId,
required: true,
auto: true,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you explain the purpose of these two attributes ? @IamRaviTejaG

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sakshamsaxena The required: true makes the _id much similar to a SQL NOT NULL column, and auto: true generates a new ObjectId automatically for every new UserSchema entry.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, then would you suggest adding these options to all the schema, or does it make sense here only? Also, link to docs for these ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I think we need to add these to all the schemas containing an _id parameter. This answer on StackOverflow explains the purpose well:
https://stackoverflow.com/questions/39871236/what-is-the-meaning-required-in-mongoose-schema

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm more curious about auto option though. required can be, and ideally should be, handled at the application level itself via validations. But why is auto necessary, is my question

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we do not have the auto: true, it throws an error to specify an _id everytime we create a new Schema object. auto: true takes care of it.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you share how you tested it out ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I simply made the appropriate routes and when I sent a GET request, it simply logged an error to the console saying it requires an _id parameter; and didn't modify the database.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright. Seems to be so. Let's rather remove the _id field from the schema instead of keeping it with options, as it was originally meant for indicative purpose only. I've tested it without the _id field, works fine, and is adding new records perfectly.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I got the error everytime I tried to do it. I'll remove it and make a new commit then. 😄

@IamRaviTejaG-zz
Copy link
Contributor Author

@sakshamsaxena Updated the UserSchema. Please review.

@sakshamsaxena sakshamsaxena merged commit e3790bb into sakshamsaxena:master Jul 22, 2018
@sakshamsaxena
Copy link
Owner

Thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants