|
@@ -84,6 +84,7 @@ var Document; // loaded lazily below //TODO: a dirty hack; need to investigate
|
|
|
klass.compare = function compare(l, r) {
|
|
|
var lt = typeof(l),
|
|
|
rt = typeof(r);
|
|
|
+
|
|
|
// Special handling for Undefined and NULL values ...
|
|
|
if (lt === "undefined") {
|
|
|
if (rt === "undefined") return 0;
|
|
@@ -103,6 +104,12 @@ klass.compare = function compare(l, r) {
|
|
|
if (isNaN(r)) return 1;
|
|
|
return l < r ? -1 : l > r ? 1 : 0;
|
|
|
}
|
|
|
+ // hack: These should really get converted to their BSON type ids and then compared, we use int vs object in queries
|
|
|
+ if (lt === "number" && rt === "object"){
|
|
|
+ return -1;
|
|
|
+ } else if (lt === "object" && rt === "number") {
|
|
|
+ return 1;
|
|
|
+ }
|
|
|
// CW TODO for now, only compare like values
|
|
|
if (lt !== rt) throw new Error("can't compare values of BSON types [" + lt + " " + l.constructor.name + "] and [" + rt + ":" + r.constructor.name + "]; code 16016");
|
|
|
// Compare everything else
|
|
@@ -124,7 +131,7 @@ klass.compare = function compare(l, r) {
|
|
|
var cmp = Value.compare(l[i], r[i]);
|
|
|
if (cmp !== 0) return cmp;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
throw new Error("logic error in Value.compare for Array types!");
|
|
|
}
|
|
|
if (l instanceof Date) return l < r ? -1 : l > r ? 1 : 0;
|