[英]How can I subtract two values and compare result in mongodb using Java driver?
Sorry for possible duplicate question... I need remove documents from a collection which have expired time calculated doing System.currentTimeMillis() - doc.lastAccess > doc.ttl
. 抱歉,可能存在重复的问题...我需要从集合中删除文档,这些文档的过期时间是通过System.currentTimeMillis() - doc.lastAccess > doc.ttl
计算System.currentTimeMillis() - doc.lastAccess > doc.ttl
。 How can I do this using BasicDBObject
query (or other most efficient/easy alternative)? 如何使用BasicDBObject
查询(或其他最有效/最简便的选择)执行此操作?
Well. 好。 I got the solution... But I read in somewhere that use $where is too slow... Can someone provide me a better approach? 我得到了解决方案...但是我读到某个地方使用$ where太慢了...有人可以为我提供更好的方法吗?
BasicDBObject q = new BasicDBObject("$where",
"new Date().getTime() - this.lastAccess > this.ttl");
this.collection.remove(q);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.