diff --git a/lib/model.js b/lib/model.js index cf2d458..329233c 100644 --- a/lib/model.js +++ b/lib/model.js @@ -89,6 +89,14 @@ var IndexModel = Model.extend({ return !!this.extra.textIndexVersion; } }, + wildcard: { + deps: ['extra', 'key'], + fn: function() { + return _.keys(this.key).some(function(k) { + return k === '$**' || k.indexOf('.$**') > -1; + }); + } + }, collation: { deps: ['extra'], fn: function() { @@ -96,7 +104,7 @@ var IndexModel = Model.extend({ } }, type: { - deps: ['geo', 'hashed', 'text'], + deps: ['geo', 'hashed', 'text', 'wildcard'], fn: function() { if (this.geo) { return 'geospatial'; @@ -107,6 +115,9 @@ var IndexModel = Model.extend({ if (this.text) { return 'text'; } + if (this.wildcard) { + return 'wildcard'; + } return 'regular'; } }, diff --git a/lib/warnings.js b/lib/warnings.js index b35b41b..b7a0258 100644 --- a/lib/warnings.js +++ b/lib/warnings.js @@ -20,7 +20,7 @@ var WARNINGS = { * * @type {string[]} */ -var VALID_INDEX_TYPE_VALUES = [1, -1, '2dsphere', '2d', 'geoHaystack', 'text', 'hashed']; +var VALID_INDEX_TYPE_VALUES = [1, -1, '2dsphere', '2d', 'geoHaystack', 'text', 'hashed', 'wildcard']; var WarningModel = Model.extend({ idAttribute: 'code', diff --git a/package-lock.json b/package-lock.json index 042e1aa..4bf30fc 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4737,7 +4737,7 @@ "lodash.defaults": "^4.2.0", "lodash.uniq": "^4.5.0", "minimist": "^1.2.0", - "pre-commit": "github:mongodb-js/pre-commit#f4158768a7ef58b46808cc09a6f6a0994c0baa67", + "pre-commit": "github:mongodb-js/pre-commit", "precinct": "^6.1.0" }, "dependencies": { diff --git a/test/fixture.js b/test/fixture.js index b7352d6..255011b 100644 --- a/test/fixture.js +++ b/test/fixture.js @@ -90,5 +90,33 @@ module.exports = [ }, 'name': 'big-index', 'ns': 'mongodb.fanclub' + }, + { + 'v': 1, + 'key': { + 'address.$**': 1 + }, + 'name': 'wildcard_single_subtree', + 'ns': 'mongodb.fanclub' + }, + { + 'v': 1, + 'key': { + '$**': 1 + }, + 'name': 'wildcard_multi_subtree', + 'wildcardProjection': { + 'borough': 1, + 'cuisine': 1 + }, + 'ns': 'mongodb.fanclub' + }, + { + 'v': 1, + 'key': { + 'name$**': 1 + }, + 'name': 'not_wildcard', + 'ns': 'mongodb.fanclub' } ]; diff --git a/test/index.test.js b/test/index.test.js index 115688f..ff1f278 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -15,7 +15,7 @@ describe('mongodb-index-model', function() { context('IndexModel', function() { it('should have all indexes in the collection', function() { - assert.equal(indexes.length, 9); + assert.equal(indexes.length, 12); }); it('should get the names right', function() { @@ -27,8 +27,12 @@ describe('mongodb-index-model', function() { 'email_1_favorite_features_1', 'last_login_-1', 'last_position_2dsphere', + 'not_wildcard', 'seniors', - 'seniors-inverse']); + 'seniors-inverse', + 'wildcard_multi_subtree', + 'wildcard_single_subtree' + ]); }); it('should have the correct namespace', function() { @@ -51,7 +55,7 @@ describe('mongodb-index-model', function() { assert.equal(index.hashed, false); assert.equal(index.geo, false); assert.equal(index.compound, false); - assert.equal(index.geo, false); + assert.equal(index.wildcard, false); assert.equal(index.partial, false); assert.equal(index.collation, false); }); @@ -60,6 +64,18 @@ describe('mongodb-index-model', function() { assert.equal(indexes.get('last_position_2dsphere', 'name').geo, true); }); + it('should recognize single wildcard indexes', function() { + assert.equal(indexes.get('wildcard_single_subtree', 'name').wildcard, true); + }); + + it('should recognize multi subtree wildcard indexes', function() { + assert.equal(indexes.get('wildcard_multi_subtree', 'name').wildcard, true); + }); + + it('should not recognize indexes with $** as wildcard', function() { + assert.equal(indexes.get('not_wildcard', 'name').wildcard, false); + }); + it('should recognize compound indexes', function() { assert.equal(indexes.get('email_1_favorite_features_1', 'name').compound, true); }); @@ -107,6 +123,7 @@ describe('mongodb-index-model', function() { assert.ok('ttl' in index); assert.ok('hashed' in index); assert.ok('geo' in index); + assert.ok('wildcard' in index); assert.ok('compound' in index); assert.ok('partial' in index); assert.ok('text' in index);