I will begin using MongoDB in a project and made the following observation: ‘Date’ must be a valid point in time, and cannot be NULL.
With MongoDB, we cannot store a NULL date, so I am guessing that the best thing to do is to simply exclude the date field from our document.
For example, if I have a ‘car’ document and a field named ‘date_sold’. If the car has not been sold yet, I simply exclude this field from the document. Once the car sells, I can add the 'date_sold' field.
By doing the above, I am assuming that I can query records for cars sold or not sold. Is this a recommended way to handle “empty” or null dates in MongoDB?
P.S. My confusion stems from the fact that since SQL has a schema, date or datetime fields can be stored as NULL, but in MongoDB, a ‘Date’ field cannot be NULL and must be a valid point in time.