Skip to content

Commit 42aa306

Browse files
committed
feat: update deps and support mongo v7
BREAKING CHANGE: Updated to MongoDB driver v6 which requires: - BSON types must be from version 6.x - Node.js version compatible with MongoDB 6.x - Updated connection patterns and BSON handling - Removed support for deprecated methods Signed-off-by: Alejandro Dominguez <[email protected]>
1 parent 8c0a6e5 commit 42aa306

8 files changed

+411
-480
lines changed

package-lock.json

+388-452
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+7-8
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"semantic-release": "SEMANTIC_COMMITLINT_SKIP=f4543f643bac890c627d538e6200c5f5a1d45ebc semantic-release",
1717
"test": "npm run test:mongoist && npm run test:native",
1818
"test:mongoist": "DRIVER=mongoist jest --forceExit",
19-
"test:native": "DRIVER=native jest && DRIVER=native DRIVER_VERSION=v3 jest",
19+
"test:native": "DRIVER=native jest",
2020
"build": "rm -rf dist/ && tsc"
2121
},
2222
"repository": {
@@ -40,7 +40,7 @@
4040
"homepage": "https://github.com/mixmaxhq/mongo-cursor-pagination#readme",
4141
"dependencies": {
4242
"base64-url": "^2.2.0",
43-
"bson": "^4.7.2",
43+
"bson": "^6.10.3",
4444
"object-path": "^0.11.8",
4545
"projection-utils": "^1.1.0",
4646
"semver": "^5.4.1",
@@ -52,21 +52,20 @@
5252
"@mixmaxhq/prettier-config": "^1.0.0",
5353
"@mixmaxhq/semantic-release-config": "^2.0.0",
5454
"@mixmaxhq/ts-config": "^1.2.1",
55+
"@types/express": "^4.17.21",
5556
"@types/jest": "^29.5.12",
5657
"@types/node": "^18.19.70",
57-
"@types/express": "^4.17.21",
5858
"@typescript-eslint/eslint-plugin": "^4.33.0",
5959
"@typescript-eslint/parser": "^4.33.0",
6060
"cz-conventional-changelog": "^3.2.0",
6161
"eslint": "^7.32.0",
6262
"eslint-config-mixmax": "^4.11.2",
6363
"jest": "^29.6.2",
6464
"mockgoose": "^8.0.4",
65-
"mongodb": "^4.8.0",
66-
"mongodb-memory-server": "6.9.6",
67-
"mongodbv3": "npm:mongodb@^3.7.4",
68-
"mongoist": "^3.0.0",
69-
"mongoose": "^5.13.20",
65+
"mongodb": "^6.15.0",
66+
"mongodb-memory-server": "^10.1.4",
67+
"mongoist": "^4.0.1",
68+
"mongoose": "^8.12.2",
7069
"prettier": "^1.19.1",
7170
"semantic-release": "^17.4.7",
7271
"ts-jest": "^29.0.5",

test/aggregate.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ describe('aggregate', () => {
1111
db: null,
1212
};
1313
beforeAll(async () => {
14-
mongod = dbUtils.start();
14+
mongod = await dbUtils.start();
1515
({ db: t.db, client } = await dbUtils.db(mongod, driver));
1616

1717
// Set up collections once for testing later.

test/find.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ describe('find', () => {
1111
db: null,
1212
};
1313
beforeAll(async () => {
14-
mongod = dbUtils.start();
14+
mongod = await dbUtils.start();
1515
({ db: t.db, client } = await dbUtils.db(mongod, driver));
1616

1717
// Set up collections once for testing later.
@@ -757,7 +757,7 @@ describe('find', () => {
757757
});
758758

759759
afterEach(async () => {
760-
await t.db.collection('test_paging_string_ids').remove({});
760+
await t.db.collection('test_paging_string_ids').deleteMany({});
761761
});
762762

763763
it('queries first few pages with next/previous', async () => {

test/findWithReq.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ describe('findWithReq', () => {
1111
db: null,
1212
};
1313
beforeAll(async () => {
14-
mongod = dbUtils.start();
14+
mongod = await dbUtils.start();
1515
({ db: t.db, client } = await dbUtils.db(mongod, driver));
1616

1717
await Promise.all([

test/search.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ describe('search', () => {
1010
db: null,
1111
};
1212
beforeAll(async () => {
13-
mongod = dbUtils.start();
13+
mongod = await dbUtils.start();
1414
({ db: t.db, client } = await dbUtils.db(mongod, driver));
1515

1616
await Promise.all([

test/support/db.ts

+8-11
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,13 @@
11
import { MongoMemoryServer } from 'mongodb-memory-server';
22
import { Db, MongoClient } from 'mongodb';
33
import mongoist from 'mongoist';
4-
import { MongoClient as MongoClientV3 } from 'mongodbv3';
5-
function start(): MongoMemoryServer {
6-
return new MongoMemoryServer({
7-
binary: { version: '6.0.8' },
8-
});
9-
}
10-
11-
const driver_version = process.env.DRIVER_VERSION;
124

5+
async function start(): Promise<MongoMemoryServer> {
6+
return await MongoMemoryServer.create();
7+
}
138
interface DbResponse {
149
db: Db;
15-
client?: MongoClient | MongoClientV3;
10+
client?: MongoClient;
1611
}
1712

1813
async function db(mongod: MongoMemoryServer, driver: string | null = null): Promise<DbResponse> {
@@ -22,8 +17,10 @@ async function db(mongod: MongoMemoryServer, driver: string | null = null): Prom
2217
db: await mongoist(uri),
2318
};
2419
}
25-
const clientToConnect = driver_version === 'v3' ? MongoClientV3 : MongoClient;
26-
const [client, dbName] = await Promise.all([clientToConnect.connect(uri), mongod.getDbName()]);
20+
const [client, dbName] = await Promise.all([
21+
MongoClient.connect(uri),
22+
mongod.instanceInfo?.dbName,
23+
]);
2724
return {
2825
db: client.db(dbName),
2926
client,

test/utils/bsonUrlEncoding.test.ts

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import * as mongo from 'mongoist';
2-
1+
import { ObjectId } from 'bson';
32
import bsonUrlEncoding from '../../src/utils/bsonUrlEncoding';
43
import * as dbUtils from '../support/db';
54

@@ -12,7 +11,7 @@ describe('bson url encoding', () => {
1211
db: null,
1312
};
1413
beforeAll(async () => {
15-
mongod = dbUtils.start();
14+
mongod = await dbUtils.start();
1615
({ db: t.db, client } = await dbUtils.db(mongod, driver));
1716
});
1817

@@ -23,7 +22,7 @@ describe('bson url encoding', () => {
2322

2423
it('encodes and decodes complex objects', async () => {
2524
const obj = {
26-
_id: mongo.ObjectID('58164d86f69ab45942c6ff38'),
25+
_id: new ObjectId('58164d86f69ab45942c6ff38'),
2726
date: new Date('Sun Oct 30 2016 12:32:35 GMT-0700 (PDT)'),
2827
number: 1,
2928
string: 'complex String &$##$-/?',

0 commit comments

Comments
 (0)