Welcome to the new MongoDB Feedback Portal!
{Improvement: "Your idea"}
We’ve upgraded our system to better capture and act on your feedback.
Your feedback is meaningful and helps us build better products.
We’ve upgraded our feedback system to better capture, track, and act on your feedback. Here’s what you need to know:
|
What problem are you trying to solve? Focus on the what and why of the need you have, not the how you'd like it solved. |
It's not possible to pass an ObjectID from a react server component to a client component without first converting to string. |
|
What would you like to see happen? Describe the desired outcome or enhancement. |
Allow native serialization of ObjectIds between react server components and client components. |
|
Why is this important to you or your team? Explain how the request adds value or solves a business need. |
It's annoying to write an object mapper just to call .toHexString. |
What steps, if any, are you taking today to manage this problem? |
Manual object mappers for each model type that calls .toHexString() on each ObjectId before serializing. |
This boundary is controlled by React's Server Components serializer, not MongoDB or Next.js. React supports only a fixed set of types with no way for libraries to register custom ones, so ObjectId can't cross natively. That'd be a React feature request (already raised and declined in react/react/issues/25687).
That being said, the pain you describe is real and it would be nice to have easier ObjectId handling like in other ecosystems. Would you mind sharing how you're currently mapping data? and how would you ideally want it to work if it were a Mongo-side solution?
Thanks, but I still have to write wrapper code for each and every object just to handle _ids. I feel like I'm fighting mongodb, and I love Mongodb, it's frustrating.
I ended up saving _id's as ULIDs instead of ObjectIds. But again it'd be nice if MongoDB played nicer with modern web frameworks and had native serialization so I don't need to write all this boilerplate code. I assume this could be a minor driver as to why people switch to prism/postgres on next.js, tbh I almost switched.
Thanks for the feedback. You don't need to write per‑model mappers. You have two ready‑made options:
JSON.stringify/JSON.parse (simplest). It's built‑in in JS, flattens every ObjectId to a string.
EJSON.serialize/EJSON.deserialize (recommended for mongo-specific data). From the
bsonpackage we ship, it's a generic mapper, similar to JSON.stringify, that preserves Mongo‑specific types (ObjectId, Decimal128, Long, dates, etc.). This turns ObjectId into a plain object (not a string though)Let us know if this helps your use case.