I have a mongoDB collection and an item in the collection looks like below:
{
"_id": "52f535b56268a019bd11cc2a",
"description": "Some description",
"entry_date": "2014-02-07T19:36:21.430Z",
"last_update": "2014-02-07T19:36:21.430Z",
"r": "samestring",
"s": "samestring"
}
Dates are ISODate objects.
This query returns items correctly
db.myCollection.find({$where : "this.entry_date < this.last_update"});
Below query returns nothing (I expect that it returns the above item):
db.myCollection.find({$where : "this.entry_date == this.last_update"});
And this query returns all items (I expected again it returns the above item):
db.myCollection.find({$where :"this.r == this.s"});
What am I doing wrong? Thanks!!
---EDIT----
So I tried to test with a small data like below:
> db.myCollection.find({},{ _id: 0, start_date: 1, end_date: 1});
{
"start_date" : ISODate("2014-02-07T19:36:21.430Z"),
"end_date" : ISODate("2014-02-07T19:36:21.430Z")
}
{
"start_date" : ISODate("2014-02-07T19:36:21.430Z"),
"end_date" : ISODate("2014-02-07T22:39:02.114Z")
}
It didn't work for Date as you can see:
> db.myCollection.find(
{$where: "Date(this.start_date) == Date(this.end_date)"},
{ _id: 0, start_date: 1, end_date: 1 }
);
{
"start_date" : ISODate("2014-02-07T19:36:21.430Z"),
"end_date" : ISODate("2014-02-07T19:36:21.430Z")
}
{
"start_date" : ISODate("2014-02-07T19:36:21.430Z"),
"end_date" : ISODate("2014-02-07T22:39:02.114Z")
}
Works for string values:
> db.myCollection.find({$where: "this.title == this.description"},{ _id: 0, title: 1 });
{ "title" : "samedescription" }