如何在MongoDB中添加TTL字段

时间:2014-10-18 14:18:54

标签: mongodb

如何在已经收集的某个元素上添加TTL(生存时间)字段(MONGODB)

如果我在集合中有一个元素(.iso文件),如下所示:

db.videos.files.find().pretty()
{
  "_id" : ObjectId("5400e505559ad1c150a3e489"),
  "chunkSize" : NumberLong(262144),
  "length" : NumberLong(754483200),
  "md5" : "093866b3f0cc342c457217892d841f96",
  "filename" : "GTA.UNDERGROUND.iso",
  "contentType" : null,
  "uploadDate" : ISODate("2014-08-29T20:39:33.019Z"),
  "aliases" : null,
  "metadata" : {
  "description" : "Grand Theft Auto",
  "tags" : [
       "Action",
       "HD"
  ]
}

如何和我在MongoDB中为此元素设置生存时间字段?

1 个答案:

答案 0 :(得分:1)

使用此

db.my_collection.update(
       {'_id': ObjectId("5400e505559ad1c150a3e489") },
       {'$set': {'TTL': 549}}, true );