I have uuid stored in MongoDB:
"transactionId" : BinData(3,"/Utm5RS0C5N2/Cwus1rrkw==")
But when I try to get this "transactionId" from PHP, I have no luck, there are no results for this query:
$query = array("transactionId" => new MongoBinData("/Utm5RS0C5N2/Cwus1rrkw==", MongoBinData::UUID));
$array = $mongo_collection->findOne($query);
var_dump($array);
How can I get this "transactionId" from php?
PS Found solution by myself. We can find hex value of "transactionId" in Mongo Shell like this:
var doc = db['ColletctionName'].findOne({"transactionId" : new BinData (3, "/Utm5RS0C5N2/Cwus1rrkw==")})
doc.transactionId.hex()
fd4b66e514b40b9376fc2c2eb35aeb93
As we see the hex value of
"transactionId" : BinData(3,"/Utm5RS0C5N2/Cwus1rrkw==")
is
fd4b66e514b40b9376fc2c2eb35aeb93
So we can query to Mongo like this to get "transactionId" field:
$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);