Skip to content

Commit

Permalink
fix: point index
Browse files Browse the repository at this point in the history
  • Loading branch information
DanRibbens committed Aug 12, 2022
1 parent 9165b25 commit b860959
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/mongoose/buildSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,13 @@ const addFieldIndex = (field: NonPresentationalField, indexFields: Index[], conf
if (config.indexSortableFields && !buildSchemaOptions.global && !field.index && !field.hidden && sortableFieldTypes.indexOf(field.type) > -1 && fieldAffectsData(field)) {
indexFields.push({ index: { [field.name]: 1 } });
} else if (field.unique && fieldAffectsData(field)) {
indexFields.push({ index: { [field.name]: 1 }, options: { unique: !buildSchemaOptions.disableUnique, sparse: field.localized || false } });
indexFields.push({
index: { [field.name]: 1 },
options: {
unique: !buildSchemaOptions.disableUnique,
sparse: field.localized || false,
},
});
} else if (field.index && fieldAffectsData(field)) {
indexFields.push({ index: { [field.name]: 1 } });
}
Expand Down Expand Up @@ -179,11 +185,12 @@ const fieldToSchemaMap: Record<string, FieldSchemaGenerator> = {
options,
})),
);
} else {
if (field.unique) {
options.unique = true;
}
indexes.push({ index: { [field.name]: direction }, options });
}
if (field.unique) {
options.unique = true;
}
indexes.push({ index: { [field.name]: direction }, options });
},
radio: (field: RadioField, schema: Schema, config: SanitizedConfig, buildSchemaOptions: BuildSchemaOptions, indexes: Index[]): void => {
const baseSchema = {
Expand Down

0 comments on commit b860959

Please sign in to comment.