JavaScript generated by driver

2 views
Skip to first unread message

Tim

unread,
Jul 21, 2010, 8:13:50 AM7/21/10
to mongodb-csharp
I was debugging one of my code and found interesting output for me.

At the MongoQueryObject.Query there was text

{ "$where": { "$code": "(((this.ServiceKey ===
4c46d7657c1a601774000002) && (this.ResourceKey ===
4c46d7657c1a601774000003)) && ((((this.Start >= 01/01/2000 10:00:00)
&& (this.Start < 01/01/2000 18:00:00)) || ((this.End > 01/01/2000
10:00:00) && (this.End <= 01/01/2000 18:00:00))) || ((this.Start <
01/01/2000 10:00:00) && (this.End > 01/01/2000 18:00:00))))" } }

As i understand from MongoDb docs after $where should be JavaScrip
code to run on server side.

Question 1: why it didn't translated into json notation to find
document ?
Answer: maybe because we have more then one condition per field

Question 2: if it is JavaScript code, why values don't have quotes
'4c46d7657c1a601774000002' and '01/01/2000 10:00:00'

Maybe better make like the following
this.End <= new Date(2000,1,1,18,0,0)

Steve Wagner

unread,
Jul 21, 2010, 8:55:26 AM7/21/10
to mongodb...@googlegroups.com
Hi Tim, thanks for figuring that out. It seems like a bug.

Can you please file a bug report in the MongoDB Jria under
MongoDB-CSharp? Thanks!

-Steve

On 21.07.2010 14:13, Tim wrote:
> I was debugging one of my code and found interesting output for me.
>
> At the MongoQueryObject.Query there was text
>
> { "$where": { "$code": "(((this.ServiceKey ===
> 4c46d7657c1a601774000002)&& (this.ResourceKey ===

> 4c46d7657c1a601774000003))&& ((((this.Start>= 01/01/2000 10:00:00)


> && (this.Start< 01/01/2000 18:00:00)) || ((this.End> 01/01/2000

> 10:00:00)&& (this.End<= 01/01/2000 18:00:00))) || ((this.Start<
> 01/01/2000 10:00:00)&& (this.End> 01/01/2000 18:00:00))))" } }

craiggwilson

unread,
Jul 21, 2010, 11:13:37 AM7/21/10
to mongodb-csharp
Definately a bug. We aren't translating DateTime's properly into
their javascript versions.

Regarding the Guids however, this might be more difficult as Guid's
are stored as binary. I'll see if this is even possible.

Thanks for reporting.

Steve Wagner

unread,
Jul 21, 2010, 11:18:51 AM7/21/10
to mongodb...@googlegroups.com
I think it would be a good idea to use the JsonFormatter for all types
you output this way.

a.

unread,
Jul 21, 2010, 11:42:03 AM7/21/10
to mongodb...@googlegroups.com
I believe you should use this construct in (mongo) javascript:

ObjectId("4c2ea999bfeddf1e54277a72")


a.

Tim

unread,
Jul 22, 2010, 2:29:34 AM7/22/10
to mongodb-csharp
fix that code in you branch

public static string SerializeForServerSide(object value)
{
...
--> sb.AppendFormat("new Date({0},{1},{2},{3},{4},{5},{6})", d.Year,
d.Month, d.Date, d.Hour, d.Minute, d.Second, d.Millisecond);
....
}
to
sb.AppendFormat("new Date({0},{1},{2},{3},{4},{5},{6})", d.Year,
d.Month, d.Day, d.Hour, d.Minute, d.Second, d.Millisecond);

Should be d.Day instead of d.Date.

:-)

craiggwilson

unread,
Jul 22, 2010, 8:05:43 AM7/22/10
to mongodb-csharp
My bad, it is fixed now.
Reply all
Reply to author
Forward
0 new messages