The MongoDB\BSON\ObjectID class

(mongodb >=1.0.0)

소개

클래스 개요

MongoDB\BSON\ObjectID implements MongoDB\BSON\Type {
/* 메소드 */
final public __construct ([ string $id ] )
final public string __toString ( void )
}

Table of Contents

add a note add a note

User Contributed Notes 2 notes

up
20
naip1984 at gmail dot com
6 years 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
3
Mike T
5 years ago
Worth noting this will throw an InvalidArgumentException if string is not in the correct format
To Top