我是meteorjs和mongodb的新手。我无法根据日期查找结果集合。首先,我使用以下meteorjs代码确认有记录。
var application = Applications.findOne({_id:'Y3xCNck6JhABGj9e7'});
var a1 = Applications.find({owner:application.owner}).map(function(app){return {owner:app.owner,createdAt:app.createdAt}});
console.log(application.createdAt); // gives Sun Dec 27 2015 09:19:17 GMT-0500 (Eastern Standard Time)
console.log(a1);
/*
This gives plenty of results. An example is
createdAt: Sun Dec 27 2015 09:16:10 GMT-0500 (Eastern Standard Time)
owner: "s4xcBwWAqSktoQuLA"
Note that the createdAt date for this particular record is before the application.createdAt, which will become relevant in the next set of queries.
*/
现在我不明白为什么这些陈述中的每一个都没有结果:
var application = Applications.findOne({_id:'Y3xCNck6JhABGj9e7'});
var a2a = Applications.find({createAt:{$lt:application.createdAt}}).map(function(app){return {owner:app.owner,createdAt:app.createdAt}});
var a2b = Applications.find({createAt:{$lt: new Date(application.createdAt)}}).map(function(app){return {owner:app.owner,createdAt:app.createdAt}});
var a2c = Applications.find({createAt:{$lte:application.createdAt}}).map(function(app){return {owner:app.owner,createdAt:app.createdAt}});
var a2d = Applications.find({createAt:{$lte: new Date(application.createdAt)}}).map(function(app){return {owner:app.owner,createdAt:app.createdAt}});
我做错了什么?在a1示例中,我确信应该有createdAt小于application.createdAt的记录。
附加说明
当我第一次保存应用程序时,我保存了日期,如下所示:
saveApplication(formVals) {
if (! Meteor.userId()) {
throw new Meteor.Error("not-authorized");
}
formVals['appStatus'] = 1;
formVals['createdAt'] = new Date();
formVals['owner'] = Meteor.userId();
formVals['username'] = Meteor.user().username;
Applications.insert(formVals);
},
答案 0 :(得分:2)
错别字:
var a2a = Applications.find({ createAt: { $lt: application.createdAt }})...
应该是
var a2a = Applications.find({ createdAt: { $lt: application.createdAt }})...