mirror of
https://github.com/parse-community/parse-server
synced 2026-08-09 13:03:18 +00:00
feat: Add support for partialFilterExpression in MongoDB storage adapter (#10346)
This commit is contained in:
@@ -502,6 +502,30 @@ describe_only_db('mongo')('MongoStorageAdapter', () => {
|
||||
expect(schemaAfterDeletion.fields.test).toBeUndefined();
|
||||
});
|
||||
|
||||
it('should create index with partialFilterExpression', async () => {
|
||||
const database = Config.get(Parse.applicationId).database;
|
||||
const adapter = database.adapter;
|
||||
|
||||
const user = new Parse.User();
|
||||
user.set('username', 'testuser');
|
||||
user.set('password', 'testpass');
|
||||
await user.signUp();
|
||||
|
||||
const schema = await new Parse.Schema('_User').get();
|
||||
const partialFilterExpression = { _email_verify_token: { $exists: true } };
|
||||
|
||||
await adapter.ensureIndex('_User', schema, ['username'], 'partial_username_index', false, {
|
||||
partialFilterExpression,
|
||||
sparse: false,
|
||||
});
|
||||
|
||||
const indexes = await adapter.getIndexes('_User');
|
||||
const createdIndex = indexes.find(idx => idx.name === 'partial_username_index');
|
||||
expect(createdIndex).toBeDefined();
|
||||
expect(createdIndex.partialFilterExpression).toEqual({ _email_verify_token: { $exists: true } });
|
||||
expect(createdIndex.sparse).toBeFalsy();
|
||||
});
|
||||
|
||||
if (process.env.MONGODB_TOPOLOGY === 'replicaset') {
|
||||
describe('transactions', () => {
|
||||
const headers = {
|
||||
|
||||
@@ -800,12 +800,17 @@ export class MongoStorageAdapter implements StorageAdapter {
|
||||
const caseInsensitiveOptions: Object = caseInsensitive
|
||||
? { collation: MongoCollection.caseInsensitiveCollation() }
|
||||
: {};
|
||||
const partialFilterOptions: Object =
|
||||
options.partialFilterExpression !== undefined
|
||||
? { partialFilterExpression: options.partialFilterExpression }
|
||||
: {};
|
||||
const indexOptions: Object = {
|
||||
...defaultOptions,
|
||||
...caseInsensitiveOptions,
|
||||
...indexNameOptions,
|
||||
...ttlOptions,
|
||||
...sparseOptions,
|
||||
...partialFilterOptions,
|
||||
};
|
||||
|
||||
return this._adaptiveCollection(className)
|
||||
|
||||
Reference in New Issue
Block a user