1

In a mongodb Schema how can I make sure that the to date is after a from date? Want to do this at a Schema level if possible.

I have a simple collection in mongodb for a football web application. This is the model created in Express for players and their first and last appearances for the team:

fname (string, required) lname (string, required) StartDate (date, required) EndDate (date)

fname and lname are verified in the Schema by create a unique compound index, so even if the web page sends a duplicate set of values the core structure is an error which can be trapped. Want to do the same with from and to dates, where the to date must always be greater than or equal to from date. Seems the right place to verify as it covers both new and updated records at the same time.

I can quite happily validate on the client side and the server side but this leads to code duplication. Any ideas? I am relatively new to web apps and brand new on mongo as I have always used MySQL.

Any help would be gratefully appreciated

Dipper17
  • 11
  • 1

0 Answers0