1

I am creating a user management module using express.js in which I have a field 'UserLastAccess' as Date in schema UserLastAccess: { type: Date} and calling Users.save() in post method.

I am unable to send null value in the above mentioned field using postman. I have tried so far "UserLastAcces": null, [], '' using body but nothing works. That field will have a date once user will be authenticated so thats why upon creation of User it has to go null.

8
  • You can skip that field altogether in the post request. Because I think you will be using new Date() in your logic when you set the date-time for that field. Commented Apr 30, 2020 at 17:44
  • Nayan, I am not setting new Date(). I think i cannot send null into a date field once its defined as type Date. Commented Apr 30, 2020 at 20:28
  • You can try default: undefined with the field if that works for you. Commented Apr 30, 2020 at 20:34
  • will try and to set date time format is there anyrhing builtin or ppl use libraries? Commented Apr 30, 2020 at 20:46
  • Explore moment very famous for handling date in JavaScript Commented Apr 30, 2020 at 20:47

1 Answer 1

1

Few possible solutions are

  • Don't send the field in the post request and it will be ignored or set to any default defined in the schema

  • You can also set the default for the field as undefined so there will be no value initially

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.