Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7682195
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T18:30:43+00:00 2026-05-31T18:30:43+00:00

Using the Java driver, what’s the best way to convert an ObjectID to/from a

  • 0

Using the Java driver, what’s the best way to convert an ObjectID to/from a string with Base64 encoding?

The ObjectIds will be part of a URL so I’d like to shorten them a bit.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T18:30:44+00:00Added an answer on May 31, 2026 at 6:30 pm

    The ObjectId class does have a toString() method, and a string may be provided in the constructor. However, these strings are base-16 (hexadecimal), and may bot be what you are looking for.

    The API information may be found here:
    http://api.mongodb.org/java/current/

    For base 64 encoding, a colleague of mine suggested that it may be preferable to use the toByteArray() method, and convert that to a base 64 string. Going the other way, the ObjectId constructor may be passed a byte array.

    A Google search for “java library base64 encoding” reveals another Stack Overflow question that contains more detail on converting byte arrays to base 64 strings and back again.
    Decode Base64 data in Java

    The above thread contains a link to the base64 class, part of the Apache Commons Codec.
    http://commons.apache.org/codec/apidocs/org/apache/commons/codec/binary/Base64.html

    Hopefully this will get you where you need to go, or at least give you some additional options to consider.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a YAML driver for the Java XStream package? I'm already using XStream
I know in Java, when using PreparedStatement with parameters, some JDBC drivers will optimize
Using Java (1.6) I want to split an input string that has components of
I am using Java back end for creating an XML string which is passed
I am using Mongodb Java driver for my Java client application. it needs to
I am trying to get info from an embedded db called NexusDB using java.
I need to know how to use where in MongoDB queries using Java Driver.
I'm using Selenium Java 2.0b3 . I have this code: ... WebDriver driver =
I'm using the MongoDB Java driver, and can't seem to get a query to
Im using the MongoDB Java driver in a java web app. One question I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.