[SERVER-21361] Javascript parsing error in shell Created: 09/Nov/15  Updated: 25/Nov/15  Resolved: 20/Nov/15

Status: Closed
Project: Core Server
Component/s: JavaScript, Querying
Affects Version/s: 3.1.9, 3.2.0-rc2
Fix Version/s: 3.2.0-rc4

Type: Bug Priority: Major - P3
Reporter: Steven Hand Assignee: Jonathan Reams
Resolution: Done Votes: 2
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
Backwards Compatibility: Fully Compatible
Operating System: ALL
Steps To Reproduce:

1) Create data set with dates
2) run query

Participants:

 Description   

A 'where' query that worked with 3.0.6 does not work with 3.1.9 and 3.2.0-rc2.

> db.datetest.find({"$where" : "(this.beginDate == null || this.beginDate > new Date()) && (this.endDate == null || this.endDate > new Date())"})
Error: error: {
	"waitedMS" : NumberLong(0),
	"ok" : 0,
	"errmsg" : "SyntaxError: expected expression, got keyword 'return' @:1:24\n",
	"code" : 139
}



 Comments   
Comment by Githook User [ 19/Nov/15 ]

Author:

{u'username': u'jbreams', u'name': u'Jonathan Reams', u'email': u'jbreams@mongodb.com'}

Message: SERVER-21361 Fix JS function body parsing
Branch: master
https://github.com/mongodb/mongo/commit/da238a94051f57bfb007396827c9366d29b1b475

Comment by Steven Hand [ 09/Nov/15 ]

The query returns the correct results and no error on 3.0.7.

db.datetest.find({"$where" : "(this.beginDate == null || this.beginDate > new Date()) && (this.endDate == null || this.endDate > new Date())"})
{ "_id" : ObjectId("5640f114bb76dada2612c444"), "count" : 4, "beginDate" : ISODate("2016-01-01T00:00:00Z"), "endDate" : ISODate("2016-01-01T00:00:00Z") }

Comment by Steven Hand [ 09/Nov/15 ]

Example data set:

 db.datetest.find().pretty()
{
	"_id" : ObjectId("5640f093bb76dada2612c441"),
	"count" : 1,
	"beginDate" : null,
	"endDate" : ISODate("2015-11-09T19:14:27.498Z")
}
{
	"_id" : ObjectId("5640f0e5bb76dada2612c442"),
	"count" : 2,
	"beginDate" : ISODate("2015-11-09T19:15:49.500Z"),
	"endDate" : ISODate("2015-11-09T19:15:49.500Z")
}
{
	"_id" : ObjectId("5640f0febb76dada2612c443"),
	"count" : 3,
	"beginDate" : ISODate("2016-01-01T00:00:00Z"),
	"endDate" : ISODate("2015-11-09T19:16:14.656Z")
}
{
	"_id" : ObjectId("5640f114bb76dada2612c444"),
	"count" : 4,
	"beginDate" : ISODate("2016-01-01T00:00:00Z"),
	"endDate" : ISODate("2016-01-01T00:00:00Z")
}
{
	"_id" : ObjectId("5640f16ebb76dada2612c445"),
	"count" : 5,
	"beginDate" : ISODate("2015-11-09T19:18:06.043Z"),
	"endDate" : null
}

Generated at Thu Feb 08 03:57:07 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.