Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/266.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从PHP查询Mongo UUID_Php_Mongodb - Fatal编程技术网

从PHP查询Mongo UUID

从PHP查询Mongo UUID,php,mongodb,Php,Mongodb,我在MongoDB中存储了uuid: "transactionId" : BinData(3,"/Utm5RS0C5N2/Cwus1rrkw==") 但当我尝试从PHP获取此“transactionId”时,我运气不佳,此查询没有结果: $query = array("transactionId" => new MongoBinData("/Utm5RS0C5N2/Cwus1rrkw==", MongoBinData::UUID)); $array = $mongo_collection

我在MongoDB中存储了uuid:

"transactionId" : BinData(3,"/Utm5RS0C5N2/Cwus1rrkw==")
但当我尝试从PHP获取此“transactionId”时,我运气不佳,此查询没有结果:

$query = array("transactionId" => new MongoBinData("/Utm5RS0C5N2/Cwus1rrkw==", MongoBinData::UUID));
$array = $mongo_collection->findOne($query);
var_dump($array);
如何从php获取此“transactionId”

PS自己找到了解决方案。我们可以在Mongo Shell中找到“transactionId”的十六进制值,如下所示:

var doc = db['ColletctionName'].findOne({"transactionId" : new BinData (3, "/Utm5RS0C5N2/Cwus1rrkw==")})
doc.transactionId.hex()
fd4b66e514b40b9376fc2c2eb35aeb93 
正如我们看到的

"transactionId" : BinData(3,"/Utm5RS0C5N2/Cwus1rrkw==")

因此,我们可以这样查询Mongo以获得“transactionId”字段:


如果你自己找到了解决方案,请随意,但不要将其编辑到问题本身。好的,谢谢,詹姆斯。有很多代码,所以我决定把它放在原来的帖子里。如果你自己找到了解决方案,请随意,但不要把它编辑成问题本身。好的,谢谢,詹姆斯。有很多代码,所以我决定把它放到原来的帖子里。
fd4b66e514b40b9376fc2c2eb35aeb93
$hex = str_replace("-", "", $transaction_id); // remove extra characters
    $msb = substr($hex, 0, 16);
    $lsb = substr($hex, 16, 16);
    $msb = substr($msb, 14, 2).substr($msb, 12, 2).substr($msb, 10, 2).substr($msb, 8, 2).substr($msb, 6, 2).substr($msb, 4, 2).substr($msb, 2, 2).substr($msb, 0, 2);
    $lsb = substr($lsb, 14, 2).substr($lsb, 12, 2).substr($lsb, 10, 2).substr($lsb, 8, 2).substr($lsb, 6, 2).substr($lsb, 4, 2).substr($lsb, 2, 2).substr($lsb, 0, 2);

    $hex = $msb.''.$lsb;
    $hex = pack('H*',$hex); 
$query = array("transactionId" => new MongoBinData ($hex , MongoBinData::UUID));
$array = $mongo_collection->findOne($query);