Sorry for possible duplicate question... I need remove documents from a collection which have expired time calculated doing System.currentTimeMillis() - doc.lastAccess > doc.ttl
. How can I do this using BasicDBObject
query (or other most efficient/easy alternative)?
Well. I got the solution... But I read in somewhere that use $where is too slow... Can someone provide me a better approach?
BasicDBObject q = new BasicDBObject("$where",
"new Date().getTime() - this.lastAccess > this.ttl");
this.collection.remove(q);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.