I am using third party API to get value from MongoDB using PHP. I get Mongo ObjectId as array of timestamp as below. How I can convert it to original MongoDB ObjectId
Array(
[timestamp] => 1573559942
[machineIdentifier] => some value
[processIdentifier] => some Value
[counter] => 8306872
[date] => 2019-11-12T11:59:02.000+0000
[time] => 1573559942000
[timeSecond] => 1573559942
)<?php
function createObjectId($arr)
{
static $inc = 0;
$ts = pack( 'N', $arr['timestamp']);
$bin = sprintf("%s%s%s%s", $ts, $arr['machineIdentifier'], $arr['processIdentifier'], $arr['counter']);
$id = '';
for ($i = 0; $i < 12; $i++ )
{
$id .= sprintf("%02X", ord($bin[$i]));
}
return new MongoID($id);
}?>--
You received this message because you are subscribed to the Google Groups "mongodb-user"
group.
For other MongoDB technical support options, see: https://docs.mongodb.com/manual/support/
---
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/8a9e0f78-6483-46e4-a7f7-e0c690859283%40googlegroups.com.
It converts it to ID but it does not match with original ID in MongoDB
To unsubscribe from this group and stop receiving emails from it, send an email to mongod...@googlegroups.com.
--
You received this message because you are subscribed to the Google Groups "mongodb-user"
group.
For other MongoDB technical support options, see: https://docs.mongodb.com/manual/support/
---
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/CACypnJUZtfQubnkQwp2-J_ykhKt56cLXNVgTsE4bRspvJCzT0A%40mail.gmail.com.
Presumably the OP is trying to reassemble the ObjectID from the parts he is getting to allow querying of the original data. In that case it does not matter that the definition is for random or non ramdom elements, but that the id is reassembled from the data he has to hand (the 'Some Values'). Its important that the regenerated id does use that data, otherwise it wont match.