Problem adding compound indexes when run in separate Node contexts #1127

Closed
kevindente opened this Issue Sep 30, 2012 · 5 comments

Comments

Projects
None yet
2 participants
@kevindente

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).

@aheckmann

This comment has been minimized.

Show comment Hide comment
@aheckmann

aheckmann Oct 1, 2012

Collaborator

can you provide something i can use to reproduce?

Collaborator

aheckmann commented Oct 1, 2012

can you provide something i can use to reproduce?

@kevindente

This comment has been minimized.

Show comment Hide comment
@kevindente

kevindente Oct 1, 2012

I'll work something up.

I'll work something up.

@kevindente

This comment has been minimized.

Show comment Hide comment
@kevindente

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.

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.

@aheckmann

This comment has been minimized.

Show comment Hide comment
@aheckmann

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

Collaborator

aheckmann commented Oct 27, 2012

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 aheckmann closed this Oct 27, 2012

@aheckmann

This comment has been minimized.

Show comment Hide comment
@aheckmann

aheckmann Oct 27, 2012

Collaborator

i submitted the fix to the driver so whenever it gets merged and published I update.

Collaborator

aheckmann commented Oct 27, 2012

i submitted the fix to the driver so whenever it gets merged and published I update.

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