In doing an ETL to get data from a Sybase database into a MongoDB backend, I can do this:
if (data.hire_date) staffProfile.hireDate = data.hire_date;
This method prevents nulls from being populated into the MongoDB. If data.hire_date has a value, then it will be dropped into staffProfile.hireDate. However, if there is no value, it effectively is ignored.
Now, I'd like to create the same result with a ternary expression. Something like:
staffProfile.hireDate = data_hireDate ? data_hireDate : null;
However, I don't want to use null here, because when I do that I end up with a bunch of nulls in the database. My question really boils down to two things: what is effectively happening in my first example, with the "if" case, when the value is not found? Is the result undefined? What could I use in the ternary syntax example to effectively write the same conditional check - right through to what is passed when the value doesn't exist?
Would this be the equivalent expression to my first example?
staffProfile.hireDate = data_hireDate ? data_hireDate : undefined;
staffProfile.hireDate: staffProfile.hireDate ?This syntax doesn't make sense - the colon should come after the question mark in a ternary, not before=, not:, when you're trying to assign a value