0

When I get the object id from mongodb that was generated by mongo itself
how can I convert/encode it to base 64 using PHP?

$_newCursor = $this->collection->findOne($urlQuery);
$_id = $_newCursor['_id'];

1 Answer 1

2

if you really need to have mongoID in base64 encoded string you need to do this:

$_newCursor = $this->collection->findOne($urlQuery);
$_id = base64_encode((string)$_newCursor['_id']);

Furthermore if you have a MongoID Object you can extract string id with:

$_id = $mongoIdObject->__ToString();
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks a lot I got confused. I tried many suggestions I'll try this one now. Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.