forked from mongodb/node-mongodb-native
-
Notifications
You must be signed in to change notification settings - Fork 0
/
createIndex.test-d.ts
35 lines (29 loc) · 1.27 KB
/
createIndex.test-d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import { expectType } from 'tsd';
import { CreateIndexesOptions, Document, MongoClient } from '../../../src';
const client = new MongoClient('');
const db = client.db('test');
const collection = db.collection('test.find');
const options: CreateIndexesOptions = { partialFilterExpression: { rating: { $exists: 1 } } };
const indexName = collection.createIndex({}, options);
expectType<Promise<string>>(indexName);
expectType<Document | undefined>(options.partialFilterExpression);
// One
collection.createIndex('someKey');
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]]);
collection.createIndex([new Map([['someKey', 1]])]);
collection.createIndex([{ a: 1, b: -1 }]);
collection.createIndex([
{ a: '2dsphere', b: -1 },
{ 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 } }]);