Skip to content

Commit 052b2e3

Browse files
committed
NODE-808 merged PR from valeri and added testcase to index_tests.js
2 parents 295fa39 + 8783596 commit 052b2e3

File tree

3 files changed

+36
-6
lines changed

3 files changed

+36
-6
lines changed

lib/db.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1046,10 +1046,12 @@ var createIndex = function(self, name, fieldOrSpec, options, callback) {
10461046
createIndexUsingCreateIndexes(self, name, fieldOrSpec, options, function(err, result) {
10471047
if(err == null) return handleCallback(callback, err, result);
10481048

1049-
// 67 = 'CannotCreateIndex', means that the server recognized
1050-
// `createIndex` as a command and so we don't need to fallback to
1051-
// an insert.
1052-
if(err.code === 67 || err.code == 11000) {
1049+
// 67 = 'CannotCreateIndex' (malformed index options)
1050+
// 85 = 'IndexOptionsConflict' (index already exists with different options)
1051+
// 11000 = 'DuplicateKey' (couldn't build unique index because of dupes)
1052+
// These errors mean that the server recognized `createIndex` as a command
1053+
// and so we don't need to fallback to an insert.
1054+
if(err.code === 67 || err.code == 11000 || err.code === 85) {
10531055
return handleCallback(callback, err, result);
10541056
}
10551057

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,13 @@
1515
"dependencies": {
1616
"es6-promise": "3.2.1",
1717
"mongodb-core": "2.0.11",
18+
"mongodb-core": "christkv/mongodb-core#2.0",
1819
"readable-stream": "2.1.5"
1920
},
2021
"devDependencies": {
2122
"JSONStream": "^1.0.7",
2223
"betterbenchmarks": "^0.1.0",
23-
"bluebird": "3.4.1",
24+
"bluebird": "3.4.3",
2425
"bson": "^0.5.1",
2526
"cli-table": "^0.3.1",
2627
"co": "4.6.0",
@@ -31,7 +32,7 @@
3132
"integra": "0.1.8",
3233
"jsdoc": "3.4.0",
3334
"ldjson-stream": "^1.2.1",
34-
"mongodb-extended-json": "1.7.0",
35+
"mongodb-extended-json": "1.7.1",
3536
"mongodb-topology-manager": "1.0.x",
3637
"mongodb-version-manager": "^1.0.6",
3738
"nyc": "^8.1.0",

test/functional/index_tests.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1023,3 +1023,30 @@ exports['should correctly create Index with sub element'] = {
10231023
});
10241024
}
10251025
}
1026+
1027+
/**
1028+
* @ignore
1029+
*/
1030+
exports['should correctly fail detect error code 85 when peforming createIndex'] = {
1031+
metadata: { requires: { topology: ['single', 'replicaset', 'sharded', 'ssl', 'heap', 'wiredtiger'], mongodb: ">=3.0.0" } },
1032+
1033+
// The actual test we wish to run
1034+
test: function(configuration, test) {
1035+
var db = configuration.newDbInstance(configuration.writeConcernMax(), {poolSize:1});
1036+
db.open(function(err, db) {
1037+
var collection = db.collection('messed_up_options');
1038+
1039+
collection.ensureIndex({ 'a.one': 1, 'a.two': 1 }, { name: 'n1', partialFilterExpression: { 'a.two': { $exists: true } } }, function(err, r) {
1040+
test.equal(null, err);
1041+
1042+
collection.ensureIndex({ 'a.one': 1, 'a.two': 1 }, { name: 'n2', partialFilterExpression: { 'a.too': { $exists: true } } }, function(err, r) {
1043+
test.ok(err);
1044+
test.equal(85, err.code);
1045+
1046+
db.close();
1047+
test.done();
1048+
});
1049+
});
1050+
});
1051+
}
1052+
}

0 commit comments

Comments
 (0)