db.log_events.createIndex( { “expireTime”: 1 }, —字段名称 { expireAfterSeconds: 0 } ) —过期时间(单位秒)
db.log_events.insert( { “expireTime”: new Date(‘Jan 22, 2016 23:00:00’), —此文档将在2016-1-22的23点自动删除 “logEvent”: 2, “logMessage”: “Success!”} )
JSONObject fpvJObj = fpvsJarr.getJSONObject(i); fpvJObj.put(“recordId”, businessControlId); DBObject dbObject = (DBObject) JSON.parse(fpvJObj.toString()); dbObject.put(“Date”, new Date()); Calendar nowTime = Calendar.getInstance(); nowTime.add(Calendar.MINUTE, 15); dbObject.put(“expireTime”, nowTime.getTime()); listObj.add(dbObject); }