Skip to content

Instantly share code, notes, and snippets.

@djfarrelly
Created April 5, 2018 22:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save djfarrelly/1358f072bf81389f03b373f19dcc11f7 to your computer and use it in GitHub Desktop.
Save djfarrelly/1358f072bf81389f03b373f19dcc11f7 to your computer and use it in GitHub Desktop.
mongo to mongodb php driver migration helpers
<?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