MongoDB汇总通过使用Epoch当前时间戳获得过期的记录
{
"id" : "58",
"topicHeader" : {
"replayData" : {
"messageDateInms" : NumberLong(1649448201357),
"messageDelayInms" : NumberLong(600000)
}
},
"status" : "IN_PROGRESS"
},
{
"id" : "59",
"topicHeader" : {
"replayData" : {
"messageDateInms" : NumberLong(1650220023677),
"messageDelayInms" : NumberLong(600000)
}
},
"status" : "IN_IROGRESS"
}
我需要根据当前的时期时间戳IE获取过期的记录 (topicheader.replaydata.messageateateinms + topicheader.replaydata.messagedelayinms)< = epoch current timestamp
我能够通过使用FIND()来解决我能够解决的(),但是试图找到更好的解决方案,因此不会引起任何绩效问题:
db.getCollection("col1").find
({
$expr: {
$lte: [{ "$add": ["$topicHeader.replayData.messageDateInms", "$topicHeader.replayData.messageDelayInms"] }, 1650226443611]
}
})
先感谢您。
{
"id" : "58",
"topicHeader" : {
"replayData" : {
"messageDateInms" : NumberLong(1649448201357),
"messageDelayInms" : NumberLong(600000)
}
},
"status" : "IN_PROGRESS"
},
{
"id" : "59",
"topicHeader" : {
"replayData" : {
"messageDateInms" : NumberLong(1650220023677),
"messageDelayInms" : NumberLong(600000)
}
},
"status" : "IN_IROGRESS"
}
i need to get the expired records based on current epoch timestamp i.e.(topicHeader.replayData.messageDateInms + topicHeader.replayData.messageDelayInms) <= epoch current timestamp
I am able to resolve by using find() but trying to find better solution so it wont cause any performance issue:
db.getCollection("col1").find
({
$expr: {
$lte: [{ "$add": ["$topicHeader.replayData.messageDateInms", "$topicHeader.replayData.messageDelayInms"] }, 1650226443611]
}
})
Thank you in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用
$ add
总结两个字段。使用$ TODATE
将它们投入到date
字段中,并与$$现在进行比较
这是 mongo playground 供您参考。
Use
$add
to sum up the 2 fields. Use$toDate
to cast them intodate
field and compare with$$NOW
Here is the Mongo playground for your reference.