Skip to content

Commit 28338a8

Browse files
authored
chore(compass-indexes): Remove index name creation, default to server naming (#3099)
1 parent 8e81190 commit 28338a8

File tree

2 files changed

+5
-31
lines changed

2 files changed

+5
-31
lines changed

packages/compass-indexes/src/modules/create-index/index.js

+3-8
Original file line numberDiff line numberDiff line change
@@ -139,11 +139,6 @@ const rootReducer = (state, action) => {
139139

140140
export default rootReducer;
141141

142-
export const createName = (f, spec) => {
143-
const n = f.map((field) => `${field.name}_${spec[field.name]}`).join('_');
144-
return n.replace(/\$\*\*/gi, 'wildcard');
145-
};
146-
147142
/**
148143
* The create index action.
149144
*
@@ -170,9 +165,9 @@ export const createIndex = () => {
170165
const options = {};
171166
options.background = state.isBackground;
172167
options.unique = state.isUnique;
173-
options.name = state.name;
174-
if (state.name === '') {
175-
options.name = createName(state.fields, spec);
168+
// The server will generate a name when we don't provide one.
169+
if (state.name !== '') {
170+
options.name = state.name;
176171
}
177172
if (state.isCustomCollation) {
178173
options.collation = state.collation;

packages/compass-indexes/src/modules/create-index/index.spec.js

+2-23
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { expect } from 'chai';
22
import sinon from 'sinon';
33

4-
import { createIndex, createName } from '../create-index';
4+
import { createIndex } from '../create-index';
55
import { HANDLE_ERROR, CLEAR_ERROR } from '../error';
66
import { TOGGLE_IN_PROGRESS } from '../in-progress';
77
import { TOGGLE_IS_VISIBLE } from '../is-visible';
@@ -148,7 +148,7 @@ describe('create index is background module', function () {
148148
);
149149
expect(errorSpy.calledOnce).to.equal(false, 'error should not be called');
150150
});
151-
it('generates name if empty', function () {
151+
it('does not generate name if empty', function () {
152152
const dispatch = (res) => {
153153
if (typeof res !== 'function') {
154154
switch (res.type) {
@@ -195,7 +195,6 @@ describe('create index is background module', function () {
195195
background: true,
196196
collation: 'coll',
197197
expireAfterSeconds: 100,
198-
name: 'abc_1',
199198
partialFilterExpression: { a: 1 },
200199
unique: true,
201200
});
@@ -266,24 +265,4 @@ describe('create index is background module', function () {
266265
expect(errorSpy.calledOnce).to.equal(true, 'error should be called');
267266
});
268267
});
269-
270-
describe('#createName', function () {
271-
context('when the index is not a wildcard index', function () {
272-
const fields = [{ name: 'name' }, { name: 'age' }];
273-
const spec = { name: 1, age: -1 };
274-
it('generates a name with all fields and directions', function () {
275-
expect(createName(fields, spec)).to.equal('name_1_age_-1');
276-
});
277-
});
278-
279-
context('when the index is a wildcard', function () {
280-
const fields = [{ name: 'name' }, { name: 'age' }];
281-
const spec = { name: '$**name.first', age: '$**age.years' };
282-
it('generates a name with all fields and wilcard replacement', function () {
283-
expect(createName(fields, spec)).to.equal(
284-
'name_wildcardname.first_age_wildcardage.years'
285-
);
286-
});
287-
});
288-
});
289268
});

0 commit comments

Comments
 (0)