Skip to content
Draft
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
2 changes: 1 addition & 1 deletion spec/schemas.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2939,7 +2939,7 @@ describe('schemas', () => {
},
},
}).then(response => {
expect(response.data.indexes.name1).toEqual({ createdAt: 1 });
expect(response.data.indexes.name1).toEqual({ _created_at: 1 });
done();
});
});
Expand Down
6 changes: 4 additions & 2 deletions src/Adapters/Storage/Mongo/MongoStorageAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
transformWhere,
transformUpdate,
transformPointerString,
transformIndicesForSchemaUpdate as transformIndexForSchemaUpdate,
} from './MongoTransform';
// @flow-disable-next
import Parse from 'parse/node';
Expand Down Expand Up @@ -286,9 +287,10 @@ export class MongoStorageAdapter implements StorageAdapter {
);
}
});
existingIndexes[name] = field;
const transformedField = transformIndexForSchemaUpdate(className, field, {fields});
existingIndexes[name] = transformedField;
insertedIndexes.push({
key: field,
key: transformedField,
name,
});
}
Expand Down
14 changes: 14 additions & 0 deletions src/Adapters/Storage/Mongo/MongoTransform.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,19 @@ const transformKey = (className, fieldName, schema) => {
return fieldName;
};

const transformIndexForSchemaUpdate = (
className,
field,
schema,
) => {
const transformedField = {};
Object.keys(field).forEach((key) => {
const transformedKey = transformKey(className, key, schema);
transformedField[transformedKey] = field[key];
});
return transformedField;
}

const transformKeyValueForUpdate = (
className,
restKey,
Expand Down Expand Up @@ -1686,4 +1699,5 @@ module.exports = {
relativeTimeToDate,
transformConstraint,
transformPointerString,
transformIndicesForSchemaUpdate: transformIndexForSchemaUpdate,
};