为什么两个等效的ISODate值不相等?

时间:2014-08-21 19:57:09

标签: mongodb

为什么最后两个语句返回false

test:PRIMARY> a = new ISODate(); b = a;
ISODate("2014-08-21T19:48:12.963Z")
test:PRIMARY> a === b;
true
test:PRIMARY> db.tmp.insert({blah:a,foo:b});
test:PRIMARY> c = db.tmp.findOne();
{
    "_id" : ObjectId("53f64d4916945e0b3a06788a"),
    "blah" : ISODate("2014-08-21T19:48:12.963Z"),
    "foo" : ISODate("2014-08-21T19:48:12.963Z")
}
test:PRIMARY> c.blah === c.foo;
false
test:PRIMARY> c.blah == c.foo;
false

1 个答案:

答案 0 :(得分:5)

它可能是比较对象引用而不是实际日期值。尝试c.blah.getTime()=== c.foo.getTime()