Skip to content

Commit 5d7b65b

Browse files
Moumoulsmtrezza
authored andcommitted
feat: upgrade to MongoDB Node.js driver 4.x for MongoDB 5.0 support (parse-community#7794)
BREAKING CHANGE: The MongoDB GridStore adapter has been removed. By default, Parse Server already uses GridFS, so if you do not manually use the GridStore adapter, you can ignore this change.
1 parent b0f16be commit 5d7b65b

11 files changed

+272
-644
lines changed

spec/AudienceRouter.spec.js

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -326,22 +326,24 @@ describe('AudiencesRouter', () => {
326326
{ name: 'My Audience', query: JSON.stringify({ deviceType: 'ios' }) },
327327
{ useMasterKey: true }
328328
).then(audience => {
329-
database.collection('test__Audience').updateOne(
330-
{ _id: audience.objectId },
331-
{
332-
$set: {
333-
times_used: 1,
334-
_last_used: now,
335-
},
336-
},
337-
{},
338-
error => {
339-
expect(error).toEqual(null);
329+
database
330+
.collection('test__Audience')
331+
.updateOne(
332+
{ _id: audience.objectId },
333+
{
334+
$set: {
335+
times_used: 1,
336+
_last_used: now,
337+
},
338+
}
339+
)
340+
.then(result => {
341+
expect(result).toBeTruthy();
340342
database
341343
.collection('test__Audience')
342344
.find({ _id: audience.objectId })
343345
.toArray((error, rows) => {
344-
expect(error).toEqual(null);
346+
expect(error).toEqual(undefined);
345347
expect(rows[0]['times_used']).toEqual(1);
346348
expect(rows[0]['_last_used']).toEqual(now);
347349
Parse._request(
@@ -361,8 +363,7 @@ describe('AudiencesRouter', () => {
361363
done.fail(error);
362364
});
363365
});
364-
}
365-
);
366+
});
366367
});
367368
});
368369

spec/FilesController.spec.js

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ const WinstonLoggerAdapter = require('../lib/Adapters/Logger/WinstonLoggerAdapte
33
.WinstonLoggerAdapter;
44
const GridFSBucketAdapter = require('../lib/Adapters/Files/GridFSBucketAdapter')
55
.GridFSBucketAdapter;
6-
const GridStoreAdapter = require('../lib/Adapters/Files/GridStoreAdapter').GridStoreAdapter;
76
const Config = require('../lib/Config');
87
const FilesController = require('../lib/Controllers/FilesController').default;
98
const databaseURI = 'mongodb://localhost:27017/parse';
@@ -24,8 +23,8 @@ const mockAdapter = {
2423
describe('FilesController', () => {
2524
it('should properly expand objects', done => {
2625
const config = Config.get(Parse.applicationId);
27-
const gridStoreAdapter = new GridFSBucketAdapter('mongodb://localhost:27017/parse');
28-
const filesController = new FilesController(gridStoreAdapter);
26+
const gridFSAdapter = new GridFSBucketAdapter('mongodb://localhost:27017/parse');
27+
const filesController = new FilesController(gridFSAdapter);
2928
const result = filesController.expandFilesInObject(config, function () {});
3029

3130
expect(result).toBeUndefined();
@@ -85,19 +84,19 @@ describe('FilesController', () => {
8584

8685
it('should add a unique hash to the file name when the preserveFileName option is false', done => {
8786
const config = Config.get(Parse.applicationId);
88-
const gridStoreAdapter = new GridFSBucketAdapter('mongodb://localhost:27017/parse');
89-
spyOn(gridStoreAdapter, 'createFile');
90-
gridStoreAdapter.createFile.and.returnValue(Promise.resolve());
87+
const gridFSAdapter = new GridFSBucketAdapter('mongodb://localhost:27017/parse');
88+
spyOn(gridFSAdapter, 'createFile');
89+
gridFSAdapter.createFile.and.returnValue(Promise.resolve());
9190
const fileName = 'randomFileName.pdf';
9291
const regexEscapedFileName = fileName.replace(/\./g, '\\$&');
93-
const filesController = new FilesController(gridStoreAdapter, null, {
92+
const filesController = new FilesController(gridFSAdapter, null, {
9493
preserveFileName: false,
9594
});
9695

9796
filesController.createFile(config, fileName);
9897

99-
expect(gridStoreAdapter.createFile).toHaveBeenCalledTimes(1);
100-
expect(gridStoreAdapter.createFile.calls.mostRecent().args[0]).toMatch(
98+
expect(gridFSAdapter.createFile).toHaveBeenCalledTimes(1);
99+
expect(gridFSAdapter.createFile.calls.mostRecent().args[0]).toMatch(
101100
`^.{32}_${regexEscapedFileName}$`
102101
);
103102

@@ -106,42 +105,42 @@ describe('FilesController', () => {
106105

107106
it('should not add a unique hash to the file name when the preserveFileName option is true', done => {
108107
const config = Config.get(Parse.applicationId);
109-
const gridStoreAdapter = new GridFSBucketAdapter('mongodb://localhost:27017/parse');
110-
spyOn(gridStoreAdapter, 'createFile');
111-
gridStoreAdapter.createFile.and.returnValue(Promise.resolve());
108+
const gridFSAdapter = new GridFSBucketAdapter('mongodb://localhost:27017/parse');
109+
spyOn(gridFSAdapter, 'createFile');
110+
gridFSAdapter.createFile.and.returnValue(Promise.resolve());
112111
const fileName = 'randomFileName.pdf';
113-
const filesController = new FilesController(gridStoreAdapter, null, {
112+
const filesController = new FilesController(gridFSAdapter, null, {
114113
preserveFileName: true,
115114
});
116115

117116
filesController.createFile(config, fileName);
118117

119-
expect(gridStoreAdapter.createFile).toHaveBeenCalledTimes(1);
120-
expect(gridStoreAdapter.createFile.calls.mostRecent().args[0]).toEqual(fileName);
118+
expect(gridFSAdapter.createFile).toHaveBeenCalledTimes(1);
119+
expect(gridFSAdapter.createFile.calls.mostRecent().args[0]).toEqual(fileName);
121120

122121
done();
123122
});
124123

125124
it('should handle adapter without getMetadata', async () => {
126-
const gridStoreAdapter = new GridFSBucketAdapter(databaseURI);
127-
gridStoreAdapter.getMetadata = null;
128-
const filesController = new FilesController(gridStoreAdapter);
125+
const gridFSAdapter = new GridFSBucketAdapter(databaseURI);
126+
gridFSAdapter.getMetadata = null;
127+
const filesController = new FilesController(gridFSAdapter);
129128

130129
const result = await filesController.getMetadata();
131130
expect(result).toEqual({});
132131
});
133132

134133
it('should reject slashes in file names', done => {
135-
const gridStoreAdapter = new GridFSBucketAdapter('mongodb://localhost:27017/parse');
134+
const gridFSAdapter = new GridFSBucketAdapter('mongodb://localhost:27017/parse');
136135
const fileName = 'foo/randomFileName.pdf';
137-
expect(gridStoreAdapter.validateFilename(fileName)).not.toBe(null);
136+
expect(gridFSAdapter.validateFilename(fileName)).not.toBe(null);
138137
done();
139138
});
140139

141140
it('should also reject slashes in file names', done => {
142-
const gridStoreAdapter = new GridStoreAdapter('mongodb://localhost:27017/parse');
141+
const gridFSAdapter = new GridFSBucketAdapter('mongodb://localhost:27017/parse');
143142
const fileName = 'foo/randomFileName.pdf';
144-
expect(gridStoreAdapter.validateFilename(fileName)).not.toBe(null);
143+
expect(gridFSAdapter.validateFilename(fileName)).not.toBe(null);
145144
done();
146145
});
147146
});

spec/GridFSBucketStorageAdapter.spec.js

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
const GridStoreAdapter = require('../lib/Adapters/Files/GridStoreAdapter').GridStoreAdapter;
21
const GridFSBucketAdapter = require('../lib/Adapters/Files/GridFSBucketAdapter')
32
.GridFSBucketAdapter;
43
const { randomString } = require('../lib/cryptoUtils');
@@ -15,25 +14,13 @@ async function expectMissingFile(gfsAdapter, name) {
1514
}
1615
}
1716

18-
describe_only_db('mongo')('GridFSBucket and GridStore interop', () => {
17+
describe_only_db('mongo')('GridFSBucket', () => {
1918
beforeEach(async () => {
20-
const gsAdapter = new GridStoreAdapter(databaseURI);
19+
const gsAdapter = new GridFSBucketAdapter(databaseURI);
2120
const db = await gsAdapter._connect();
2221
await db.dropDatabase();
2322
});
2423

25-
it('a file created in GridStore should be available in GridFS', async () => {
26-
const gsAdapter = new GridStoreAdapter(databaseURI);
27-
const gfsAdapter = new GridFSBucketAdapter(databaseURI);
28-
await expectMissingFile(gfsAdapter, 'myFileName');
29-
const originalString = 'abcdefghi';
30-
await gsAdapter.createFile('myFileName', originalString);
31-
const gsResult = await gsAdapter.getFileData('myFileName');
32-
expect(gsResult.toString('utf8')).toBe(originalString);
33-
const gfsResult = await gfsAdapter.getFileData('myFileName');
34-
expect(gfsResult.toString('utf8')).toBe(originalString);
35-
});
36-
3724
it('should save an encrypted file that can only be decrypted by a GridFS adapter with the encryptionKey', async () => {
3825
const unencryptedAdapter = new GridFSBucketAdapter(databaseURI);
3926
const encryptedAdapter = new GridFSBucketAdapter(
@@ -451,7 +438,7 @@ describe_only_db('mongo')('GridFSBucket and GridStore interop', () => {
451438
await db.admin().serverStatus();
452439
expect(false).toBe(true);
453440
} catch (e) {
454-
expect(e.message).toEqual('topology was destroyed');
441+
expect(e.message).toEqual('MongoClient must be connected to perform this operation');
455442
}
456443
});
457444
});

spec/GridStoreAdapter.spec.js

Lines changed: 0 additions & 111 deletions
This file was deleted.

0 commit comments

Comments
 (0)