MongoDB shell version: 3.2.6
connecting to: test
> db.log_events.createIndex( { "createdAt": 1 }, { expireAfterSeconds: 3600 } )
{
"createdCollectionAutomatically" : true,
"numIndexesBefore" : 1,
"numIndexesAfter" : 2,
"ok" : 1
}
> db.log_events.insert( {
... "createdAt": new Date(),
... "logEvent": 2,
... "logMessage": "Success!"
... } )
WriteResult({ "nInserted" : 1 })
> db.log_events.getIndexes()
[
{
"v" : 1,
"key" : {
"_id" : 1
},
"name" : "_id_",
"ns" : "test.log_events"
},
{
"v" : 1,
"key" : {
"createdAt" : 1
},
"name" : "createdAt_1",
"ns" : "test.log_events",
"expireAfterSeconds" : 3600
}
]
> db.log_events.find()
> db.runCommand( {"collMod" :'log_events',"index" :{keyPattern:{"createdAt" : 1}, expireAfterSeconds: 60}})
{
"expireAfterSeconds_old" : NumberLong(3),
"expireAfterSeconds_new" : 60,
"ok" : 1
}
> db.log_events.getIndexes()
[
{
"v" : 1,
"key" : {
"_id" : 1
},
"name" : "_id_",
"ns" : "test.log_events"
},
{
"v" : 1,
"key" : {
"createdAt" : 1
},
"name" : "createdAt_1",
"ns" : "test.log_events",
"expireAfterSeconds" : NumberLong(60)
}
]
> db.log_events.insert( { "createdAt": new Date(), "logEvent": 2, "logMessage": "Success!" } )
WriteResult({ "nInserted" : 1 })
> db.log_events.find()
{ "_id" : ObjectId("5784c14f6a85d96ed4d42113"), "createdAt" : ISODate("2016-07-12T10:07:11.349Z"), "logEvent" : 2, "logMessage" : "Success!" }
> db.log_events.find()
{ "_id" : ObjectId("5784c14f6a85d96ed4d42113"), "createdAt" : ISODate("2016-07-12T10:07:11.349Z"), "logEvent" : 2, "logMessage" : "Success!" }
> db.log_events.find()
{ "_id" : ObjectId("5784c14f6a85d96ed4d42113"), "createdAt" : ISODate("2016-07-12T10:07:11.349Z"), "logEvent" : 2, "logMessage" : "Success!" }
> db.log_events.find()
{ "_id" : ObjectId("5784c14f6a85d96ed4d42113"), "createdAt" : ISODate("2016-07-12T10:07:11.349Z"), "logEvent" : 2, "logMessage" : "Success!" }
> db.log_events.find()
{ "_id" : ObjectId("5784c14f6a85d96ed4d42113"), "createdAt" : ISODate("2016-07-12T10:07:11.349Z"), "logEvent" : 2, "logMessage" : "Success!" }
> Date()
Tue Jul 12 2016 18:11:32 GMT+0800 (SGT)
// The ISODate is in UTC.
> new Date()
ISODate("2016-07-12T10:08:47.861Z")
> db.log_events.find()
>
No comments:
Post a Comment