Skip to content

Commit 640995e

Browse files
committed
feat
1 parent e71e030 commit 640995e

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

spec/MongoStorageAdapter.spec.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,30 @@ describe_only_db('mongo')('MongoStorageAdapter', () => {
502502
expect(schemaAfterDeletion.fields.test).toBeUndefined();
503503
});
504504

505+
it('should create index with partialFilterExpression', async () => {
506+
const database = Config.get(Parse.applicationId).database;
507+
const adapter = database.adapter;
508+
509+
const user = new Parse.User();
510+
user.set('username', 'testuser');
511+
user.set('password', 'testpass');
512+
await user.signUp();
513+
514+
const schema = await new Parse.Schema('_User').get();
515+
const partialFilterExpression = { _email_verify_token: { $exists: true } };
516+
517+
await adapter.ensureIndex('_User', schema, ['username'], 'partial_username_index', false, {
518+
partialFilterExpression,
519+
sparse: false,
520+
});
521+
522+
const indexes = await adapter.getIndexes('_User');
523+
const createdIndex = indexes.find(idx => idx.name === 'partial_username_index');
524+
expect(createdIndex).toBeDefined();
525+
expect(createdIndex.partialFilterExpression).toEqual({ _email_verify_token: { $exists: true } });
526+
expect(createdIndex.sparse).toBeFalsy();
527+
});
528+
505529
if (process.env.MONGODB_TOPOLOGY === 'replicaset') {
506530
describe('transactions', () => {
507531
const headers = {

src/Adapters/Storage/Mongo/MongoStorageAdapter.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -800,12 +800,17 @@ export class MongoStorageAdapter implements StorageAdapter {
800800
const caseInsensitiveOptions: Object = caseInsensitive
801801
? { collation: MongoCollection.caseInsensitiveCollation() }
802802
: {};
803+
const partialFilterOptions: Object =
804+
options.partialFilterExpression !== undefined
805+
? { partialFilterExpression: options.partialFilterExpression }
806+
: {};
803807
const indexOptions: Object = {
804808
...defaultOptions,
805809
...caseInsensitiveOptions,
806810
...indexNameOptions,
807811
...ttlOptions,
808812
...sparseOptions,
813+
...partialFilterOptions,
809814
};
810815

811816
return this._adaptiveCollection(className)

0 commit comments

Comments
 (0)