i am storing one start time and end time in db.Again i would not again to store any start and end time by using that same start and end time or between of that start and end time .how to do that?
example initially i am saving like this
db.save({"start":1am,"end":2am});
again i wouldn't allow to save like this
db.save({"start":1.15am "end":3pm});
or
db.save({"start":1am,"end":1.45am});
but we can allow to save like this
db.save({"start":12am ,"end":1am});
or db.save({"start":"3am" "end":4am});
how to do with mongodb. Advance thanks
You have to check if the new object meets your business rule before saving it. There's no way to condition an insert/save statement. Run a query to check if there's another document with a date range that collides with the new one, then you can save the new doc. But you have to do it in the client side, not in the DB server.
If you really need the server to check the business rule, there's a way to store a javascript function in the server. That way you can make this function check your rules and insert/save a document if the validation passes. However this is not recommended, use it as a last resort. Here is how to store javascript in the server.