[SERVER-6172] Differences in db.<collection>.drop() and db.<collection>.remove({}) Created: 22/Jun/12  Updated: 15/Aug/12  Resolved: 22/Jun/12

Status: Closed
Project: Core Server
Component/s: Sharding, Shell
Affects Version/s: 2.0.6
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: James Short Assignee: Unassigned
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Mac OSX 10.7.4
RHEL 6.1


Operating System: OS X
Participants:

 Description   

We have automated testing that loads data into a given state using mongoimport with json fixture data. To make sure the database is clean, we have been using --drop on mongo import which I believe to be equivalent to running db.<collection>.drop() prior to the mongoimport. However, now that we are testing against a sharded mongo deployment, we have changed the test code to do the following:

sh "#

{MONGO_BIN}mongo #{DB_HOST}/#{DB_NAME} --quiet --eval \"db.#{collectionName}.remove({})\""
sh "#{MONGO_BIN}

mongo #

{DB_HOST}

/#

{DB_NAME}

--quiet --eval \"db.adminCommand('flushRouterConfig')\""

To preserve sharding between test runs. However, now we see intermittent failures on a piece of code that 'stamps' documents based on a given association algorithm and it is returning intermittent results. It seems that maybe db.<collection>.remove({}) is asynchronous or something like that. Maybe the algorithm is sensitive to order it gets data from a collection and that .remove({}) followed by an import makes the ordering of the data different?

Also to note is that we see this behavior on non sharded mongo instances (when developers test on their local dev machine)

I guess my goal of this JIRA (in the event it is working as designed) is to understand the fundamental differences between .drop() and .remove().

Thanks



 Comments   
Comment by Eliot Horowitz (Inactive) [ 22/Jun/12 ]

remove( {} ) iterates every document deleting it.
This can take a while.

With the code you're using, its a fire and forget write, so the data might still be there when it returns.

You should do:

sh "#

{MONGO_BIN}

mongo #

{DB_HOST}

/#

{DB_NAME}

--quiet --eval \"db.#

{collectionName}

.remove({}); db.getLastError();\""

to block until it finishes.

Generated at Thu Feb 08 03:10:56 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.