Skip to content

Commit

Permalink
feat(NODE-3651): add hashed index type (mongodb#3432)
Browse files Browse the repository at this point in the history
  • Loading branch information
zendagin authored and ZLY201 committed Nov 5, 2022
1 parent 0d7d6fa commit 6f7b942
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/operations/indexes.ts
Expand Up @@ -50,7 +50,16 @@ const VALID_INDEX_OPTIONS = new Set([
]);

/** @public */
export type IndexDirection = -1 | 1 | '2d' | '2dsphere' | 'text' | 'geoHaystack' | number;
export type IndexDirection =
| -1
| 1
| '2d'
| '2dsphere'
| 'text'
| 'geoHaystack'
| 'hashed'
| number;

function isIndexDirection(x: unknown): x is IndexDirection {
return (
typeof x === 'number' || x === '2d' || x === '2dsphere' || x === 'text' || x === 'geoHaystack'
Expand Down
2 changes: 2 additions & 0 deletions test/types/community/createIndex.test-d.ts
Expand Up @@ -18,6 +18,7 @@ collection.createIndex(['someKey', 1]);
collection.createIndex(new Map([['someKey', 1]]));
collection.createIndex({ a: 1, b: -1 });
collection.createIndex({ a: '2dsphere', b: -1 });
collection.createIndex({ a: 'hashed' });
// OrMore
collection.createIndex(['someKey']);
collection.createIndex([['someKey', 1]]);
Expand All @@ -28,6 +29,7 @@ collection.createIndex([
{ a: 'geoHaystack', b: 1 }
]);
collection.createIndex(['a', ['b', 1], { a: 'geoHaystack', b: 1 }, new Map([['someKey', 1]])]);
collection.createIndex([{ a: 'hashed' }]);

// @ts-expect-error: CreateIndexes now asserts the object value types as of NODE-3517
collection.createIndexes([{ key: { a: 34n } }]);

0 comments on commit 6f7b942

Please sign in to comment.