Join GitHub today
GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
Problem adding compound indexes when run in separate Node contexts #1127
Comments
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Show comment Hide comment
can you provide something i can use to reproduce? |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Show comment Hide comment
kevindente
commented
Oct 1, 2012
I'll work something up. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Show comment Hide comment
kevindente
Oct 4, 2012
OK, here's a gist that repro's the problem:
https://gist.github.com/3836058
It looks like this is only a problem when the schema is constructed before the connection is open, causing the commands to get queued. In that case, the ensureIndex command gets executed in the original context, not the child context. OTOH, if the connection is open, then the indexes are created in the same context as the schema definition, and there's no problem.
kevindente
commented
Oct 4, 2012
OK, here's a gist that repro's the problem: It looks like this is only a problem when the schema is constructed before the connection is open, causing the commands to get queued. In that case, the ensureIndex command gets executed in the original context, not the child context. OTOH, if the connection is open, then the indexes are created in the same context as the schema definition, and there's no problem. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Show comment Hide comment
aheckmann
Oct 27, 2012
Collaborator
ok just ran this, thanks for putting the test case together. this is a bug in the driver. I'll close this and open a ticket there instead and refer to this. https://github.com/mongodb/node-mongodb-native/issues/754
ok just ran this, thanks for putting the test case together. this is a bug in the driver. I'll close this and open a ticket there instead and refer to this. https://github.com/mongodb/node-mongodb-native/issues/754 |
aheckmann
closed this
Oct 27, 2012
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Show comment Hide comment
aheckmann
Oct 27, 2012
Collaborator
i submitted the fix to the driver so whenever it gets merged and published I update.
i submitted the fix to the driver so whenever it gets merged and published I update. |
kevindente commentedSep 30, 2012
If the Schema's declared in JS that's running in a secondary context (via vm.runInNewContext), creating compound indexes via Schema.index({field: 1, ...}) fails. The ensureIndex fails when that part runs in a different context from the Schema definition.
The problem appears to be with DbCommand.createCreateIndexCommand(). In that function it compares the constructor of fieldOrSpec to Object to determine if it's an object literal. But because the fieldOrSpec was declared in a different context, the comparison fails (see joyent/node#1518 for more info).