无法在 mongodb atlas 数据 api 中使用日期时间戳进行查询

发布于 2025-01-15 04:00:03 字数 759 浏览 0 评论 0原文

通过 mongo data api 传递时无法使用日期进行查询。我想查询数据库以查找当时获取的所有条目

下面的代码返回空文档

示例数据库:

[{
  sensorId:'1231541',
  sensorTimestamp:'2022-01-28T20:14:26.223+00:00'
}]


await superagent.post(`${url}/action/${body.action}`)
       .send({
        dataSource: 'Cluster0',
        database:'testDB',
        collection: body.collection,       
        filter: body.filter,
        sort: body.sort,        
      });


const config = {
  action: 'find',
  collection: 'testCollection',
  filter: {
    sensorId: '1231541',
    sensorTimestamp: {
      $gte:  new Date('2022-01-28T20:14:26.223+00:00'),
      $lt: new Date('2022-01-28T20:33:16.324+00:00'),
    },
  },
  sort: {
    name: 1,
  },
};

Unable to query using date while passing through mongo data api. I would like to query the database to find fetch all entries at the time

The below code returns empty document

The sample db :

[{
  sensorId:'1231541',
  sensorTimestamp:'2022-01-28T20:14:26.223+00:00'
}]


await superagent.post(`${url}/action/${body.action}`)
       .send({
        dataSource: 'Cluster0',
        database:'testDB',
        collection: body.collection,       
        filter: body.filter,
        sort: body.sort,        
      });


const config = {
  action: 'find',
  collection: 'testCollection',
  filter: {
    sensorId: '1231541',
    sensorTimestamp: {
      $gte:  new Date('2022-01-28T20:14:26.223+00:00'),
      $lt: new Date('2022-01-28T20:33:16.324+00:00'),
    },
  },
  sort: {
    name: 1,
  },
};

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

南巷近海 2025-01-22 04:00:03

您必须以毫秒为单位查询日期,而不是其字符串表示形式。

You must query dates in millis, not tje string representation of that.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文