php 插入mongodb uuid类型

$luuid ='e4eaaaf2-d142-11e1-b3e4-080027620cdd'; //格式一定要正确 » RFC 4122.

$uuid='0123456789abcdef';
$id = new \MongoDB\BSON\Binary($uuid,\MongoDB\BSON\Binary::TYPE_UUID);

查mongodb的LUUID类型为以下代码:

$luuid= str_replace("-","",$luuid);
$id= new \MongoDB\BSON\Binary(hex2bin($luuid),\MongoDB\BSON\Binary::TYPE_OLD_UUID);
$id=bin2hex($id);
var_dump($id);

php 插入mongodb uuid类型
标签: