Thanks for the reply!
On Thu, Dec 9, 2010 at 9:30 PM, Alvin Richards <al...@10gen.com> wrote:
> So how $where is processed is documented here
>
> http://www.mongodb.org/display/DOCS/Server-side+Code+Execution
>
> When a $where is processed, the JavaScript is evaluated server side
> for each of the documents. The built in operators (e.g. $or, $in etc.)
> will be BSON datatype aware as you point out. In this case, the BSON
> type is getting converted to the closest JavaScript type for the
> evaluation of your expression. The problem is inconsistent datatypes.
Actually, as far as I can tell, the inconsistent datatypes saved me
from getting back no results at all -- although perhaps that would
have been easier to debug.
The problem is the non-obvious behavior of == in Mongo JavaScript
expressions. I would expect a comparison of the same value of the same
type, NumberLong(1) == NumberLong(1), to be true, when in fact it is
false. I would also expect a comparison of the same value of different
types to perhaps be false, even using == instead of ===, but in fact,
1 == NumberLong(1) is true.
> Assuming that you can't force the datatypes to be consistent during
> the insert you solutions seems to be the obvious one. However, I need
> to dig further to understand why the 'String(this.a) ==
> String(this.b)' did not return all the documents.
>
> -Alvin
String(NumberLong(1)) != String(1) because "NumberLong(1)" != "1".
Certainly, I should be ensuring that the correct datatypes are stored
in my database. Using both types of comparison was simply a quick fix,
and I can drop the 'this.a == this.b' branch when I perform the cleanup.
-Eric
> --
> You received this message because you are subscribed to the Google Groups "mongodb-user" group.
> To post to this group, send email to mongod...@googlegroups.com.
> To unsubscribe from this group, send email to mongodb-user...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/mongodb-user?hl=en.
>
>