Skip to content
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

Switches from drop to removeMany #31

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Switches from drop to removeMany #31

wants to merge 1 commit into from

Conversation

jperkelens
Copy link

It seems like many people (myself included) were receiving sporadic errors about mongodb background operations. This is because the drop command also clears indices for the collection, forcing mongodb to reindex the next time the collection is used. Switching the command from drop to removeMany keeps the indices intact and prevents this from happening.

@powmedia
Copy link
Owner

What kind of errors are you seeing?

@jperkelens
Copy link
Author

Here's an example stack trace:

Unhandled rejection MongoError: exception: cannot perform operation: a background operation is currently running for collection** users
    at Function.MongoError.create (/somepath/node_modules/pow-mongodb-fixtures/node_modules/mongodb/node_modules/mongodb-core/lib/error.js:31:11)
    at /somepath/node_modules/pow-mongodb-fixtures/node_modules/mongodb/node_modules/mongodb-core/lib/topologies/server.js:793:66
    at bound (domain.js:254:14)
    at runBound (domain.js:267:12)
    at Callbacks.emit (.../node_modules/pow-mongodb-fixtures/node_modules/mongodb/node_modules/mongodb-core/lib/topologies/server.js:94:3)
    at null.messageHandler (/somepath/node_modules/pow-mongodb-fixtures/node_modules/mongodb/node_modules/mongodb-core/lib/topologies/server.js:235:23)
    at Socket.<anonymous> (/somepath/node_modules/pow-mongodb-fixtures/node_modules/mongodb/node_modules/mongodb-core/lib/connection/connection.js:294:20)
    at Socket.emit (events.js:107:17)
    at readableAddChunk (_stream_readable.js:163:16)
    at Socket.Readable.push (_stream_readable.js:126:10)
    at TCP.onread (net.js:538:20)

@powmedia
Copy link
Owner

What are the implications of using removeMany() over drop() when it comes
to indexes? The MongoDB docs say that drop() removes the indices on a
collection as well. Do you know what happens with them when using
removeMany instead?

On Mon, Mar 21, 2016 at 1:50 PM Jan Paul Erkelens [email protected]
wrote:

Here's an example stack trace:

Unhandled rejection MongoError: exception: cannot perform operation: a background operation is currently running for collection** users
at Function.MongoError.create (/somepath/node_modules/pow-mongodb-fixtures/node_modules/mongodb/node_modules/mongodb-core/lib/error.js:31:11)
at /somepath/node_modules/pow-mongodb-fixtures/node_modules/mongodb/node_modules/mongodb-core/lib/topologies/server.js:793:66
at bound (domain.js:254:14)
at runBound (domain.js:267:12)
at Callbacks.emit (.../node_modules/pow-mongodb-fixtures/node_modules/mongodb/node_modules/mongodb-core/lib/topologies/server.js:94:3)
at null.messageHandler (/somepath/node_modules/pow-mongodb-fixtures/node_modules/mongodb/node_modules/mongodb-core/lib/topologies/server.js:235:23)
at Socket. (/somepath/node_modules/pow-mongodb-fixtures/node_modules/mongodb/node_modules/mongodb-core/lib/connection/connection.js:294:20)
at Socket.emit (events.js:107:17)
at readableAddChunk (_stream_readable.js:163:16)
at Socket.Readable.push (_stream_readable.js:126:10)
at TCP.onread (net.js:538:20)


You are receiving this because you commented.

Reply to this email directly or view it on GitHub
#31 (comment)

@jperkelens
Copy link
Author

removeMany() keeps the indices intact, however, since the document is being removed the entry in the index should be removed as well and should not grow the index indefinitely.

Since its common practice to clear/load your data in a beforeEach test setup, I tended to encounter this error 20-35% of the time I ran my tests. If you are running a test suite multiple times, your collection indices are unlikely to change. If you'd like to keep a command in this library that does drop collections I recommend creating a new command (drop perhaps?) that can be called at the end of the test suite.

@jperkelens
Copy link
Author

Just wanted to check in to make sure my last comment answered your questions.

@BorntraegerMarc
Copy link

@jperkelens The repo owner isn't around anymore...

I've forked the project and published an own package: https://www.npmjs.com/package/mongodb_fixtures

Feel free to use it 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants