For one of my collections, which must remain unix timestamp instead of isodate, I usually convert the timestamp with new Date(unix_timestamp).
Now I need the ne
For additional calculated fields in projection you need to use $add operator, like this: (console example)
db.so.aggregate([{$project: {date: {$add: Date() }}}])
but it's wrong and we get a error message:
exception: $add does not support strings (or dates)
But I found a simple hack =)
db.so.aggregate([{$project: {date: {$substr: [Date(), 0, -1] }}}])
In this case we'll have expected result with dates Also, in PHP output you can see error like this:
exception: disallowed field type Date in object expression (at 'date')
And now, solution(php 5.4 syntax):
$so->aggregate([
['$project' => ["date" => ['$substr' => [new MongoDate(), 0, -1]] ] ]
]);