{ "entryDate" : "2012-10-14T00:00:00.000Z", "amount" : 1, "cardId" : "50786621e3b983f1078d0bc9", "_id" : ObjectId("507a17354c6cbd6a4b000001"), "addedDate" : "Sat Oct 13 2012 21:36:53 GMT-0400 (EDT)" }
{ "entryDate" : "2012-10-10T00:00:00.000Z", "amount" : 21, "cardId" : "50786639e3b983f1078d205e", "_id" : ObjectId("507a17394c6cbd6a4b000002"), "addedDate" : "Sat Oct 13 2012 21:36:57 GMT-0400 (EDT)" }
{ "entryDate" : "2012-10-09T00:00:00.000Z", "amount" : 1, "cardId" : "50786639e3b983f1078d205e", "_id" : ObjectId("507a25e46af510804c000002"), "addedDate" : "Sat Oct 13 2012 22:39:32 GMT-0400 (EDT)" }
{ "entryDate" : "2012-10-08T00:00:00.000Z", "amount" : 12, "cardId" : "50786621e3b983f1078d0bc9", "_id" : ObjectId("507a2603b7a095824c000003"), "addedDate" : "Sat Oct 13 2012 22:40:03 GMT-0400 (EDT)" }
{ "entryDate" : "2012-10-08T00:00:00.000Z", "amount" : 1, "cardId" : "507865e1e3b983f1078ceb3f", "_id" : ObjectId("507a2667b7a095824c000004"), "addedDate" : "Sat Oct 13 2012 22:41:43 GMT-0400 (EDT)" }
{ "entryDate" : "2012-10-15T00:00:00.000Z", "amount" : 2, "cardId" : "50786621e3b983f1078d0bc9", "_id" : ObjectId("507a48c170b1a26f4f000001"), "addedDate" : "Sun Oct 14 2012 01:08:17 GMT-0400 (EDT)" }
这是我要执行的查询:(这是集合)
// (these are JS Date objects)
// start = Sun Oct 7 2012 13:22:02 GMT-0400 (EDT)
// end = Sat Oct 20 2012 13:22:02 GMT-0400 (EDT)
this.find({ cardId: cardId, entryDate: { $lt : start, $gt : end } }).toArray(function(err, entries) { console.log(err, entries) });
但不幸的是,它总是返回[]并且没有错误.
有任何想法吗?我肯定做错了事,但是我已经搜索了很长时间了,所以我要求您的帮助.
非常感谢,今天过得愉快!
解决方法:
尝试这个:
this.find({ cardId: cardId, entryDate: { $lt : start, $gt : end } }).toArray(function(err, entries) { console.log(err, entries) });
这是我测试的方式.插入脚本如下所示:
db.samples.insert({ "entryDate" : new Date(2012, 10, 9), "amount" : 1, "cardId" : "50786639e3b983f1078d205e" })
查找查询是这个:
db.samples.find({ entryDate: { $gt : new Date(2012, 10, 7), $lt : new Date(2012, 10, 20) } }).count();
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。