Created
April 5, 2018 22:13
-
-
Save djfarrelly/1358f072bf81389f03b373f19dcc11f7 to your computer and use it in GitHub Desktop.
mongo to mongodb php driver migration helpers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class MongoId implements Serializable, JsonSerializable | |
{ | |
public $id; | |
public function __construct($id) | |
{ | |
$this->id = (string) $id; | |
} | |
public function getObjectId() | |
{ | |
return new MongoDB\BSON\ObjectID($this->id); | |
} | |
public function serialize() | |
{ | |
return serialize($this->id); | |
} | |
public function jsonSerialize() | |
{ | |
return (string) $this->id; | |
} | |
public function unserialize($id) | |
{ | |
$this->id = (string) $id; | |
} | |
public function __toString() | |
{ | |
return (string) $id; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment