New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
assigning mongoose documents to the session causes it to die a violent death #17
Comments
What does the code you're using to assign a mongoose doc look like? |
(superuser is a mongoose document) |
Sorry for hijacking the thread, but I am also receiving errors when storing objects in the session record that were assigned from Mongoose documents. If relevant, the problem does not occur if I first translate objects using Document.toObject() from Mongoose, which converts an in-memory document object model to a plain JavaScript Object instance. And, I understand that this might be necessary. What I don't understand is what Mongoose could be adding to an object's fields such that assigning them directly to the session as fields is then later causing this otherwise obscure error. For this case, the "response" object has the following composition:
I then execute a manual save as I have express-session "resave" turned off:
At the completion callback, err is set as follows:
|
A mongoose document is a very complex object. For instance, if you do
Would not recommend saving this to mongodb directly. Just use |
@vkarpov perhaps add a note about this in the documentation. |
@r3wt I think this should actually be fixed with newer versions of mongoose (try >= 4.7.7 re Automattic/mongoose#4866). If it still doesn't work, please provide a code sample that demonstrates your issue. |
@vkarpov15 well i came here from google, and the version of mongoose i am running is 4.7.6, i'll try 4.7.7 and let you know if it works. But i decided against storing the object anyway, instead just storing the user id. |
yeah that's a good idea. Let me know if the new mongoose version fixes it 👍 |
In a few (rare) cases I need to just assign a mongoose document to the session for quick/easy lookup. I realize it's probably not a wonderful idea, and that I should probably store and id and load it, etc etc etc. Granted.
However, in connect-mongo this worked great; in connect-mongodb-session I get a maximum call stack exceeded and it all explodes in a giant burning fireball of death. What do you think of the idea of having .toObject applied to any object assigned to the session which supports that method? Alternatively one could JSON.stringify and then JSON.parse before saving, which would be extremely effective at making sure it's serializable, but... well, pros and cons to that too.
Thoughts?
The text was updated successfully, but these errors were encountered: