I see you have have tagged this with mongodb-php
so I assume you are using PHP. MongoDB does have a $currentDate
operator but currently there is no way to actually set an offset to that date.
For example I tried @diwakar's answer on 3.0:
> db.table_1.update({"id":1 },{completion_time: { $add: [ "$currentDate", 90 ] }})
2015-03-23T11:22:05.497+0000 E QUERY Error: field names cannot start with $ [$add]
at Error (<anonymous>)
at DBCollection._validateForStorage (src/mongo/shell/collection.js:160:19)
at DBCollection._validateForStorage (src/mongo/shell/collection.js:164:18)
at DBCollection._validateUpdateDoc (src/mongo/shell/collection.js:387:14)
at Object.findOperations.updateOne (src/mongo/shell/bulk_api.js:675:20)
at DBCollection.update (src/mongo/shell/collection.js:454:22)
at (shell):1:12 at src/mongo/shell/collection.js:160
So currently this needs to be done client side like so:
$mongo->collection->insert(['completion_time' => new MongoDate(time() + (60*90))])
It seems that is the only way.