feat: Disable index-field validation to create index for fields that don't yet exist (#8137)
This commit is contained in:
@@ -421,6 +421,14 @@ describe_only_db('mongo')('GridFSBucket', () => {
|
||||
expect(gfsResult.toString('utf8')).toBe(twoMegabytesFile);
|
||||
});
|
||||
|
||||
it('properly upload a file when disableIndexFieldValidation exist in databaseOptions', async () => {
|
||||
const gfsAdapter = new GridFSBucketAdapter(databaseURI, { disableIndexFieldValidation: true });
|
||||
const twoMegabytesFile = randomString(2048 * 1024);
|
||||
await gfsAdapter.createFile('myFileName', twoMegabytesFile);
|
||||
const gfsResult = await gfsAdapter.getFileData('myFileName');
|
||||
expect(gfsResult.toString('utf8')).toBe(twoMegabytesFile);
|
||||
});
|
||||
|
||||
it('properly deletes a file from GridFS', async () => {
|
||||
const gfsAdapter = new GridFSBucketAdapter(databaseURI);
|
||||
await gfsAdapter.createFile('myFileName', 'a simple file');
|
||||
|
||||
@@ -3008,6 +3008,7 @@ describe('schemas', () => {
|
||||
beforeEach(async () => {
|
||||
await TestUtils.destroyAllDataPermanently(false);
|
||||
await config.database.adapter.performInitialization({ VolatileClassesSchemas: [] });
|
||||
databaseAdapter.disableIndexFieldValidation = false;
|
||||
});
|
||||
|
||||
it('cannot create index if field does not exist', done => {
|
||||
@@ -3036,6 +3037,29 @@ describe('schemas', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('can create index if field does not exist with disableIndexFieldValidation true ', async () => {
|
||||
databaseAdapter.disableIndexFieldValidation = true;
|
||||
await request({
|
||||
url: 'http://localhost:8378/1/schemas/NewClass',
|
||||
method: 'POST',
|
||||
headers: masterKeyHeaders,
|
||||
json: true,
|
||||
body: {},
|
||||
});
|
||||
const response = await request({
|
||||
url: 'http://localhost:8378/1/schemas/NewClass',
|
||||
method: 'PUT',
|
||||
headers: masterKeyHeaders,
|
||||
json: true,
|
||||
body: {
|
||||
indexes: {
|
||||
name1: { aString: 1 },
|
||||
},
|
||||
},
|
||||
});
|
||||
expect(response.data.indexes.name1).toEqual({ aString: 1 });
|
||||
});
|
||||
|
||||
it('can create index on default field', done => {
|
||||
request({
|
||||
url: 'http://localhost:8378/1/schemas/NewClass',
|
||||
|
||||
Reference in New Issue
Block a user