无法在 mongodb atlas 数据 api 中使用日期时间戳进行查询
通过 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您必须以毫秒为单位查询日期,而不是其字符串表示形式。
You must query dates in millis, not tje string representation of that.