查询MongoDB的日期时,TypeORM返回空数组

时间:2020-08-28 17:24:58

标签: mongodb typeorm

我有以下查询,该查询应该从我的MongoDB中获取具有将来HospitalizedUntil日期的对象:

        return await this.hospitalRepository.find({
        where: {
            hospitalizedUntil: MoreThanDate(new Date(), EDateType.Datetime)
        }
    });

更多日期:

const MoreThanDate = (date: Date, type: EDateType) => MoreThan(format(date, type));

但是,此查询不会返回任何对象,即使Mongo中将来有一个对象也可以将HospitaledUntil放置在该对象中: (当前日期时间:2020-08-28T17:11:09.888Z)

[
  Hospital {
    _id: 5f492efd50e81f63dc60c5d3,
    discordId: 'xxxxxxxxxxxxxxxxx',
    hospitalizedUntil: 2020-08-28T18:51:17.627Z,
    reason: 'Was robbed',
    hospitalizedBy: 'xxxxxxxxxxxxxxxxx'
  }
]

我也尝试过使用Between运算符:

    where: {
        hospitalizedUntil: Between(new Date(), new Date('9999-12-31'))
    }

但这也会返回一个空数组。

1 个答案:

答案 0 :(得分:0)

遇到了同样的问题,使用原生 mongoDB 查询解决了。

hospitalizedUntil: { $gte: format(new Date(), EDateType.Datetime) }

我认为这些函数在 mongoDB 上不起作用(尽管我没有发现与该问题相关的任何内容)