Last active
December 17, 2015 22:58
-
-
Save sowe/5685534 to your computer and use it in GitHub Desktop.
MongoDB utilitis for PDI (Pentaho Data Integration)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function toDate (ts){ | |
try{ | |
if(! isNullAndUndefined(ts)){ | |
var ps = mongoEvaluation(ts).$date; | |
var firstsplit = ps.split("T"); | |
var date = firstsplit[0]; | |
var time = firstsplit[1]; | |
var datesplit = date.split("-"); | |
var timesplit = time.split(":"); | |
var secondsplit = timesplit[2].split("."); | |
var d2 = new Date(datesplit[0], datesplit[1], datesplit[2], timesplit[0], timesplit[1], secondsplit[0], secondsplit[1].replace("Z","")).getTime(); | |
return d2; | |
} else { | |
var d2 = new Date(); | |
return d2.getTime(); | |
} | |
} catch(err){ | |
var d2 = new Date().getTime(); | |
return d2; | |
} | |
} | |
function mongoEvaluation (value){ | |
try{ | |
var tmp2; | |
eval("tmp2 = " + aux); | |
if(!(tmp2 instanceof Array)) { | |
return tmp2; | |
}else{ | |
return tmp2; | |
} | |
} catch(err){ | |
} | |
} | |
function isNullAndUndefined (aux,value){ | |
if(aux){ | |
return aux; | |
}else{ | |
return value; | |
} | |
} | |
function isNullAndUndefined (aux){ | |
if(aux){ | |
return true; | |
}else{ | |
return false; | |
} | |
} | |
function typeMongoCast(valueMongo){ | |
var regObjectId = [a-z| 0-9]; | |
if ((valueMongo.value.match(regObjectId)){ | |
return "ffffffffffffffffffffffff"; | |
} else { | |
return valueMongo; | |
} | |
} | |
function ObjectIdToId(ObjectId){ | |
return parseInt( ObjectId, 16 ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment