为什么最后两个语句返回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
答案 0 :(得分:5)
它可能是比较对象引用而不是实际日期值。尝试c.blah.getTime()=== c.foo.getTime()