Skip to content

Instantly share code, notes, and snippets.

@asya999
Created July 15, 2015 19:37
Show Gist options
  • Save asya999/fdb5ecde9d1949691fbc to your computer and use it in GitHub Desktop.
Save asya999/fdb5ecde9d1949691fbc to your computer and use it in GitHub Desktop.
getTypes = function (field) {
var alltypes=[
{ t: "Regex", minv: Timestamp(2147483647,9999) },
{ t: "Timestamp", minv: Timestamp(0,0) },
{ t: "ISODate", minv: new Date(0,0,0) },
{ t: "True", minv: true },
{ t: "False", minv: false },
{ t: "ObjectId", minv: ObjectId("000000000000000000000000") },
{ t: "BinData", minv: BinData(0,"") },
{ t: "Array", minv: [] },
{ t: "Subdocument", minv: {} },
{ t: "String", minv: "" },
{ t: "Number", minv: NumberLong("-9223372036854775807") },
{ t: "Null", minv: null }
] ;
var maxPos=alltypes.length;
var con=[];
con[maxPos]="Other/Unknown";
for (pos = maxPos-1; pos > -1; pos--) {
con[pos] = {"$cond":{
if: {$gte:[field, alltypes[pos]["minv"] ]},
then: alltypes[pos]["t"],
else: con[pos+1]
}};
}
return con[0];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment