Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/66.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs 从mongodb获取日期为今天的项目列表_Angularjs_Node.js_Mongodb_Express - Fatal编程技术网

Angularjs 从mongodb获取日期为今天的项目列表

Angularjs 从mongodb获取日期为今天的项目列表,angularjs,node.js,mongodb,express,Angularjs,Node.js,Mongodb,Express,我想从我的MongoDB中获得一份日期为今天的项目列表。当我在下面的pushups.js文件中硬编码日期时,我只得到我想要的结果:“date:”2017-10-26T07:09:36.417Z 这是我的密码 我的MongoDB中的文档 { "_id": { "$oid": "59f18ac290531423ecb3cb51" }, "date": "2017-10-26T07:09:36.417Z", "count": "25" } 俯卧撑.js

我想从我的MongoDB中获得一份日期为今天的项目列表。当我在下面的
pushups.js
文件中硬编码日期时,我只得到我想要的结果:
“date:”2017-10-26T07:09:36.417Z

这是我的密码

我的MongoDB中的文档

{
    "_id": {
        "$oid": "59f18ac290531423ecb3cb51"
    },
    "date": "2017-10-26T07:09:36.417Z",
    "count": "25"
}
俯卧撑.js

router.get(“/pushupsToday”,函数(req,res){
var dateObj=新日期();
console.log(dateObj);
find({“date”:dateObj},函数(err,俯卧撑){
如果(错误){
res.send(err);
}
res.status(200).send({“success”:true,“result”:俯卧撑});
});
俯卧撑.service.ts

@Injectable()
导出类PushupService{
apiUrl=this.appSettings.getApiURL();
数据;
删除项ID;
移除项目;
构造函数(公共http:http、公共appSettings:appSettings){
}
公共事务{
返回此文件。http
.get(this.apirl+'api/pushupsToday')
.map(response=>response.json().result);
}
home.ts

getTodays(){
log(“getTodays in home.ts”);
this.pushupSeriesToday=this.pushupService.getTodays();
}
home.html


{{item.count}}-{{item.date | date}

我认为在将日期保存到数据库之前,您可以使用moment js更改日期的格式

var currentDate = moment(new Date()).format('MM-DD-YYYY');

因此,您可以轻松地对其进行筛选。

我认为您可以在将日期保存到数据库之前使用MomentJS更改日期的格式

var currentDate = moment(new Date()).format('MM-DD-YYYY');

因此,您可以轻松地对其进行筛选。

这是行不通的,有一个很好的理由。请理解。嘿,感谢您的帮助。我使用了moment.js,下面是我如何解决它的:var currentDate=moment(new Date()).format(“YYYY-MM-DD”);var currentDateS=currentDate+“T00:00:00:000Z”;var currentDate=currentDate+”T23:59:59:000Z“;db.pushups.find({“date”):{$gte:currentDateS,$lt:currentDateE}},@MrTots很高兴我能帮上忙。这不管用,有很好的理由。并且理解。嘿,谢谢你的帮助。我使用了moment.js,下面是我如何解决它的:var currentDate=moment(new date()).format(“YYYY-MM-DD”)var currentDateS=currentDate+“T00:00:00:000Z”;var currentDate=currentDate+“T23:59:59:000Z”;db.pushups.find({“date”):{$gte:currentDateS,$lt:currentDate}},@MrTots很高兴我能帮忙。“day”实际上是“今天开始”和“明天”之间可能值的“范围”。一天实际上是“范围”“今天的开始”和“明天”之间的可能值。