Can't return MongoIds from +page.server.js load function #7470
-
When I query my Db to get an array of users, all comes with it's MongID. I get the error:
So, to workaround this issue I need to iterate all over the array and convert each I think this is not good. I am missing something? Regards |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
As the error says, you can't return non-POJO objects from To quote the docs:
Question: why do you think this is not good - is it because you require the functionality of the Id on the front-end? What would you expect to happen? And how have you coped before sending Mongo data from server to client, and could that inform this? One straightforward way to turn a richer object into a POJO - preserving its data, but stripping its functionality - is
(or similar) from your |
Beta Was this translation helpful? Give feedback.
-
Finally I wrapped with a I insist this is annoying and not dev friendly as SK claims |
Beta Was this translation helpful? Give feedback.
As the error says, you can't return non-POJO objects from
+page.server.js
. That is to say: if it's an object that also has methods/prototype methods on it, you get this error. That's because it's a client/server interaction - the.server*
page runs in a Node environment, not a browser environment, and sends data over the network, so of course all it can return is plain JSON.To quote the docs:
Question: why do you think this is not good