在MongoDB查询JSON对象中使用日期

在MongoDB查询JSON对象中使用日期,json,mongodb,meteor,Json,Mongodb,Meteor,我有一个函数,它可以根据许多条件为我创建查询对象: compileSearchCriteria(search){ var conditions = { published: true }; conditions["publishedDate"] = {$lte: new Date(search.searchDate)}; <more code here> return cond

我有一个函数,它可以根据许多条件为我创建查询对象:

compileSearchCriteria(search){
        var conditions = {
            published: true
        };
        conditions["publishedDate"] = {$lte: new Date(search.searchDate)};

        <more code here>

        return conditions;
    },
并且什么也不返回

db.trips.find({"published":true,"publishedDate":{"$lt":ISODate("2016-03-27T15:48:41.866Z")}})
返回所需的结果。直接发送查询也可以:

DealsCollection.find({published:true, publishedDate:{$lt: new Date(this.props.searchDate)}}).fetch()
如何创建查询对象以获得正确的结果

更新
它应该有效,而且确实有效。问题似乎在于Meteor中的mini mongo实现。我把电话分开,看看断开的地方在哪里。服务器使用原始查询返回数据。但是查询mini-mongo集合中的结果文档不会产生任何结果,尽管我可以在其中看到返回的文档。这是另一个问题。谢谢你的指点。

这可能是错误的语法,它应该工作
db.trips.find({“published”:true,“publishedDate”:{“$lt”:“2016-03-27T15:48:41.866Z”})
在mongo shell中不会产生任何结果
db.trips.find({“published”:true,“publishedDate”:{“$lt”:ISODate(“2016-03-27T15:48:41.866Z”)}
生成结果。我通常使用日期对象而不是ISOString,它会被mongo自动转换,还尝试使用
$lte
,因此如果是同一日期,它会检测到它,例如:
var date=new date()
db.trips.find({“published”:true,“publishedDate”:{“$lte”:date}}})
你可以用
date.setUTCDate
修改日期,它可能会使用错误的语法
db.trips.find({“published”:true,“publishedDate”:{“$lt:“2016-03-27T15:48:41.866Z})
在mongo shell中不会产生任何结果
db.trips.find({“published”:true,“publishedDate”:{“$lt”:ISODate(“2016-03-27T15:48:41.866Z”)}
生成结果。我通常使用日期对象而不是ISOString,它会被mongo自动转换,还尝试使用
$lte
,因此如果是同一日期,它会检测到它,例如:
var date=new date()
db.trips.find({“published”:true,“publishedDate”:{“$lte”:date}})
并且您可以使用
date.setUTCDate
DealsCollection.find({published:true, publishedDate:{$lt: new Date(this.props.searchDate)}}).fetch()