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

Unable to create Mongoose compound indexes when running under Railway #203

Closed
kevindente opened this Issue Sep 29, 2012 · 2 comments

Comments

Projects
None yet
2 participants

This issue is complicated, and I don't pretend to understand all the subtleties of what's going on here. In my app I'm using a customSchema to access the database with Mongoose directly. It's been working fine, until I tried adding compound indexes for a schema, and it started failing in really mysterious way (basically as if the object literal that was passed in as the index specifier was an empty object but it isn't).

After several hours of tracing through code, I think what's happening is that Railway is running the schema.js file in a new Node context, and the object literal defining the index fields is added to Mongoose at that point. However, later when the Mongoose call to the native driver's ensureIndex actually fires, it's happening in a different context, and the object literal index specifier no longer works (specifically, the driver checks that the literal's constructor property equals Object, but the check fails). I believe it's the same issue described:
joyent/node#1518

I'm not sure what the solution is here.

Collaborator

anatoliychakkaev commented Sep 29, 2012

There are only one solution: do not run in new context, because all root
objects are unique in each context and this is a feature of node, not bug.
But mongoose's type checking is wrong from this point of view because they
are blindly expect that their code will be executed in one context. I don't
get idea why this restriction is necessary for mongoose. Probably this is a
point for discussions with mongoose authors. I'm not sure, maybe there's a
lack of understanding and they have real reasons to do that. Need to
discuss and investigate. I believe mongoose authors are open for this kind
of questions.

From our side we can throw out some features we have now when running in
new context and just use common context in schema (maybe optionally).

On Sat, Sep 29, 2012 at 4:11 AM, Kevin Dente notifications@github.comwrote:

This issue is complicated, and I don't pretend to understand all the
subtleties of what's going on here. In my app I'm using a customSchema to
access the database with Mongoose directly. It's been working fine, until I
tried adding compound indexes for a schema, and it started failing in
really mysterious way (basically as if the object literal that was passed
in as the index specifier was an empty object but it isn't).

After several hours of tracing through code, I think what's happening
is that Railway is running the schema.js file in a new Node context, and
the object literal defining the index fields is added to Mongoose at that
point. However, later when the Mongoose call to the native driver's
ensureIndex actually fires, it's happening in a different context, and the
object literal index specifier no longer works (specifically, the driver
checks that the literal's constructor property equals Object, but the check
fails). I believe it's the same issue described:
joyent/node#1518 joyent/node#1518

I'm not sure what the solution is here.


Reply to this email directly or view it on GitHubhttps://github.com/1602/express-on-railway/issues/203.

Thanks. I'll report it to the Mongoose project too, see if they want to do anything on their side.

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