Frequently, I extract the data from mongo database using java (because I have to do it across very large number of collection across many databases). In the process, I generally use
Eg:
time = ((myObject.containsField("time"))) ? (myObject.get("time").toString().isEmpty()) ? "Empty" : myObject.get("time").toString() : "NA";
to make sure if the string exists or it is empty. but how do we do a null check, I mean if time has a value null
Eg: time=null
How do we extract the value to script so that I can save it to the extract as some string which represents null value?
.get is resulting in to a NullPointerException. This is a run time check and I often extract more than 20 values for each record. What is the best way to do a null check?
your help is much appreciated. Thanks in advance!! :)
"null"ornullmyObjectisn't null, then the returned .get("time") object is.. thus.get()isn't throwing the NPE, buttoString()is.. I'll modify the answer below.