Skip to content
This repository was archived by the owner on May 17, 2021. It is now read-only.

Wildcard indexes #61

Merged
merged 1 commit into from
Jun 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion lib/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,22 @@ 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() {
return !!this.extra.collation;
}
},
type: {
deps: ['geo', 'hashed', 'text'],
deps: ['geo', 'hashed', 'text', 'wildcard'],
fn: function() {
if (this.geo) {
return 'geospatial';
Expand All @@ -107,6 +115,9 @@ var IndexModel = Model.extend({
if (this.text) {
return 'text';
}
if (this.wildcard) {
return 'wildcard';
}
return 'regular';
}
},
Expand Down
2 changes: 1 addition & 1 deletion lib/warnings.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions test/fixture.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
];
23 changes: 20 additions & 3 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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() {
Expand All @@ -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);
});
Expand All @@ -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);
});
Expand Down Expand Up @@ -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);
Expand Down