Error when dropping a collection

65 views
Skip to first unread message

Andreas Saebjoernsen

unread,
Jun 10, 2012, 2:36:41 PM6/10/12
to mon...@googlegroups.com
I am working on a Mongoid 3.0 port of carrierwave-mongoid. The specs 
drop a collection that may or may not exist, but I am getting an error if
the collection does not exist. Please let me know if this is the expected
behavior or a bug.

You can see the spec I am working on here:

I drop a collection like this:
      MongoUser.collection.drop

If the collection does not exist I get:

     Moped::Errors::OperationFailure:
       The operation: #<Moped::Protocol::Command
         @length=71
         @request_id=36
         @response_to=0
         @op_code=2004
         @flags=[:slave_ok]
         @full_collection_name="carrierwave_test.$cmd"
         @skip=0
         @limit=-1
         @selector={:drop=>:users}
         @fields=nil>
       failed with error "ns not found"
     # ./spec/mongoid_spec.rb:50:in `block (2 levels) in <top (required)>'

In the spec you can see that I am currently doing a workaround that is
insufficient going forward:

     describe CarrierWave::Mongoid do
        after do
            if MongoUser.all.size > 0
               MongoUser.collection.drop
            end
     end
     ...

Please let me know if this behavior is expected or a bug.

Best,
Andy

Durran Jordan

unread,
Jun 11, 2012, 4:11:13 AM6/11/12
to mon...@googlegroups.com
Yeah I think we should just fail silently on these instead of raising an error, since when I drop a non-existent collection in the mongo console it simply returns false.

2012/6/10 Andreas Saebjoernsen <and...@digitalplaywright.com>

Andreas Saebjoernsen

unread,
Jun 11, 2012, 10:27:52 AM6/11/12
to mon...@googlegroups.com
Thank you for looking into this. Returning false would simplify the call. Do you want me to create an issue in the issue tracker for changing 'Book.collection.drop' to return false if 'Book.collection' does not exist? 

Durran Jordan

unread,
Jun 11, 2012, 10:30:44 AM6/11/12
to mon...@googlegroups.com
Yes please, I'll need the reminder there as I am trying to get all the rc issues cleaned up for release. :)

2012/6/11 Andreas Saebjoernsen <and...@digitalplaywright.com>

Andreas Saebjoernsen

unread,
Jun 11, 2012, 11:13:05 AM6/11/12
to mon...@googlegroups.com
I have created the following issue for this email thread:

The issue describes the change in semantics from your previous email.

Thank you.

Andy
Reply all
Reply to author
Forward
0 new messages