MongoDB\Driver\CursorId::getTimestamp() ?

18 views
Skip to first unread message

Момчил Божинов

unread,
Apr 23, 2016, 1:52:26 PM4/23/16
to mongodb-user
Hello,

I am missing a method in the new PHP driver

it used to be gettimestamp and functionality seems to be missing

Tried searching in mongo-php-library-master but search came up empty

Help!

Momchil

Derick Rethans

unread,
Apr 24, 2016, 5:01:47 AM4/24/16
to mongodb-user
On Sat, 23 Apr 2016, Момчил Божинов wrote:

> I am missing a method in the new PHP driver
>
> it used to be gettimestamp
> <http://docs.php.net/manual/en/mongoid.gettimestamp.php> and functionality
> seems to be missing
>
> Tried searching in mongo-php-library-master but search came up empty

This feature request is being tracked at
https://jira.mongodb.org/browse/PHPC-552 and
https://jira.mongodb.org/browse/HHVM-216

You can workaround it currently, as is shown at:
https://github.com/alcaeus/mongo-php-adapter/blob/ef2f253ba47e376ba220ba1cde753c99a51e2705/lib/Mongo/MongoId.php#L174

cheers,
Derick

--
{
website: [ "http://mongodb.org", "http://derickrethans.nl" ],
twitter: [ "@derickr", "@mongodb" ]
}

Момчил Божинов

unread,
Apr 24, 2016, 6:42:07 AM4/24/16
to mongodb-user
I seems to work, but 
I when I do the find I have to loose the existing type map settings (e.g. ['root' => 'array', 'document' => 'array']) and work with objects

Not much of a problem, but an inconvenience

Thank you
Momchil

Derick Rethans

unread,
Apr 25, 2016, 6:59:01 AM4/25/16
to mongodb-user
You should not need to change the typemap. The following works:

<?php
$manager = new \MongoDB\Driver\Manager;
$query = new \MongoDB\Driver\Query( [] );

$cursor = $manager->executeQuery( 'dramio.checkins', $query );
$cursor->setTypeMap( ['root' => 'array', 'document' => 'array'] );

$results = $cursor->toArray();

echo hexdec(substr((string) $results[0]['_id'], 0, 8)), "\n";
?>

(outputs "1452730554").
Reply all
Reply to author
Forward
0 new messages