PHP 7.4.0 alpha 1 Released

La clase MongoDB\BSON\ObjectID

(mongodb >=1.0.0)

Introducción

Sinopsis de la Clase

MongoDB\BSON\ObjectID implements MongoDB\BSON\Type {
/* Métodos */
final public MongoDB\BSON\ObjectId::__construct ([ string $id ] )
final public MongoDB\BSON\ObjectId::getTimestamp ( void ) : int
final public MongoDB\BSON\ObjectId::serialize ( void ) : string
final public MongoDB\BSON\ObjectId::__toString ( void ) : string
final public MongoDB\BSON\ObjectId::unserialize ( string $serialized ) : void
}

Tabla de contenidos

add a note add a note

User Contributed Notes 2 notes

up
10
naip1984 at gmail dot com
1 year ago
I struggled for awhile to identify the way to find() using a ObjectID

This seems to work, I hope this helps someone else out. 

$mongoId = '5a2493c33c95a1281836eb6a';

$collection->find(['_id'=> new MongoDB\BSON\ObjectId("$mongoId")]);

I found it here:   https://docs.mongodb.com/php-library/current/reference/method/MongoDBCollection-findOne/

Note this is for the PHP library, not the legacy library.
up
2
Mike T
1 year ago
Worth noting this will throw an InvalidArgumentException if string is not in the correct format
To Top