【发布时间】:2021-04-22 16:23:45
【问题描述】:
我是 mongodb 的新手。我有一个名为 conEnd 的日期字段,其值为“2020-01-18T16:26:00.000+00:00”。
我需要检查一个条件,当前日期时间大于或等于conEnd 日期时间,取消订阅套接字。
这是我的代码。
const today = new Date();
today.setDate(today.getDate());
const date = (today.getDate() < 10) ? '0' + today.getDate() : today.getDate();
const month = (today.getMonth() < 10) ? '0' + (today.getMonth() + 1) : today.getMonth() + 1;
const currentDate = today.getFullYear() + '-' + month + '-' + date;
const hours = today.getHours();
const minutes = today.getMinutes();
const currentdatetime:any= '2021-01-18T16:26:00.000+00:00'//for testing I hard code the time. Otherwise I used currentDate+'T'+hours+':'+minutes+':00.000+00:00';
我在 mongodb 中有一个与当前时间匹配的字段。但是每当我使用下面的代码时,我都会得到空数组 []。
this.stockcontests.find({conEnd:currentdatetime},{conEnd:1}, function (err, result) {
if (err){
console.log(err)
}else{
console.log(result)
}
});
没有条件{conEnd : currentdatetime},上面的查询以这种格式给我conEnd:
conEnd: 2020-01-18T16:26:00.000Z
我也试过检查这种情况,但失败了{conEnd : {$gte : currentdatetime} }
如何正确执行条件,conEnd >= currentdatetime?
【问题讨论】: