Created
July 15, 2015 19:37
-
-
Save asya999/fdb5ecde9d1949691fbc to your computer and use it in GitHub Desktop.
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
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