Uploaded image for project: 'Node.js Driver'
  1. Node.js Driver
  2. NODE-352

Create collection is not failing if the collection already exists

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 1.4.29
    • Affects Version/s: None
    • Component/s: None
    • Labels:

      This is probably a regression due to this commit - https://github.com/mongodb/node-mongodb-native/commit/940850b891100547e94daa6b5e4b4737b6cde73b

      In line 1035, this conditional check seems to be the problem.

      if(err && err.code && err.code != 48 && options && options.strict) return callback(err, null);

      In case of collection already exists error, there is no code being returned. Below is the error returned by the runCommand.

      { [MongoError: collection already exists] name: 'MongoError', ok: 0, errmsg: 'collection already exists' }

      Not sure whether err.code check is required over there (maybe some hack), but if it is something that is needed for 2.8 then it could be written as

      if(err && (!err.code || err.code && err.code != 48) && options && options.strict)

            Assignee:
            christkv Christian Amor Kvalheim
            Reporter:
            prabhus Prabhu Subramanian
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: