0

I am having trouble querying mongodb using user's birth date. The client application is sending birth date as a string in "MM-DD-YYYY" format. I am getting no result although the user is an my database. How do I structure my application query in order to convert date inside a string to ISODate?

Here is the client request

{"firstName": "Mark",
  "lastName": "Tony",
  "birthDate": "06-25-1990"
}

Here is my query

db.user.findOne({
  'firstname': req.body.firstName,
  'lastname': req.body.lastName,
  'dob': req.body.birthDate
});

2 Answers 2

1

First of all make sure you convert dob object into date format from the client side and convert object received on server into date too.

var date = new Date(req.body.birthDate) //converting into date format 
date = date.toISOString() // converting to iso format date 

similarly send data to server from client side in similar manner ! I hope this helps

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

Comments

0

Use JS Date object to convert string to ISO Date.

More Info : JS Date Object

1 Comment

Not enough detail, please reference which parts of the link you added to your response actually answer the question. Need to be specific. Read the SO guidelines before posting.

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.