[SERVER-6992] "collection already exists" error misses code Created: 10/Sep/12  Updated: 05/Apr/17  Resolved: 26/Oct/16

Status: Closed
Project: Core Server
Component/s: Diagnostics
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Minor - P4
Reporter: Gustavo Niemeyer Assignee: Kyle Suarez
Resolution: Done Votes: 1
Labels: neweng
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Backwards Compatibility: Fully Compatible
Operating System: ALL
Participants:

 Description   

Creating a duplicate collection is a common error cases that needs a comparison to differentiate real errors from expected behavior, and unfortunately it misses a code at the moment:

[LOG] 37.79905 Socket 0xf84014d540 to localhost:54424: received document: bson.M

{"ok":0, "errmsg":"collection already exists"}

 Comments   
Comment by Kyle Suarez [ 26/Oct/16 ]

I'm resolving this as Gone Away since in all instances we do include an error code for "collection already exists": either 17399 or 48, depending on the exact path taken in the code.

Comment by Ian Whalen (Inactive) [ 30/Sep/16 ]

this can probably be resolved once someone checks to confirm that we're now including an error code.

Comment by Gustavo Niemeyer [ 18/Sep/12 ]

Consistency is great, but it's currently sitting at the wrong side.

As a data point, this is part of the stock documentation for the Node driver:

db.createCollection('test', function(err, collection) {});

This command will create the collection on the Mongo DB database before returning the collection object. If the collection already exists it will ignore the creation of the collection.

db.createCollection('test', {safe:true}, function(err, collection) {});

The {safe:true} option will make the method return an error if the collection already exists.

In other words, stock documentation is suggesting skipping all errors and simply assume they know what's going on.

Another data point: this is the current create_collection routine of the Ruby driver:

      if strict? && !collection_names.include?(name.to_s)
        raise Mongo::MongoDBError, "Collection #{name} doesn't exist. " +
          "Currently in strict mode."
      else
        opts = opts.dup
        opts[:safe] = opts.fetch(:safe, @safe)
        opts.merge!(:pk => @pk_factory) unless opts[:pk]
        Collection.new(name, self, opts)
      end

In good faith, it's attempting to handle the situation internally to clean up the API. Unfortunately, it introduces a race condition in the code that will cause the user logic to explode if the collection happens to be created between the test and the action.

The root cause for these is lack of information about the error, which forces people to either test for error strings or ignore the error entirely assuming they know what it is, and both of these examples come from experienced MongoDB people. People in the wild are not doing much better.

Comment by Eliot Horowitz (Inactive) [ 18/Sep/12 ]

No normal command failures have error codes.
Don't think this should be special.

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