Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Expose mongoose object directly: 'RangeError: Maximum call stack size exceeded' #30

Closed
simonspoerri opened this Issue Aug 24, 2012 · 4 comments

Comments

Projects
None yet
5 participants

I'm trying to directly expose a mongoose object within the callback of the mongoose's find method. When calling res.expose(mongooseObject, 'mongooseObjectName') this results in a the following error:

RangeError: Maximum call stack size exceeded

I don't know if this is an error caused by mongoose or by expose. Does anybody know what's happening here and how i could fix it?

Owner

tj commented Sep 1, 2012

did you look at the stack trace? it will tell you

premjg commented Sep 29, 2012

Didn't get a chance to take a peek under the hood but this hack worked for me.

res.expose(
  {objectLabel: JSON.parse(JSON.stringify(object))}
)

Don't ask how I stumbled on this :)

@tj tj closed this Oct 22, 2012

gregwym commented Aug 15, 2013

@premjg Using toObject or toJSON is probably a better solution.

res.expose(
  { objectLabel: mongooseDoc.toObject() }
)

@premjg @gregwym I have used this method but the issue is that my data have a field for date and it is not being escaped, thus resulting in javascript error. Any suggestion?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment