Skip to content

Commit 1774f8d

Browse files
committed
fix tests for mongodb 8
1 parent c807d53 commit 1774f8d

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@
126126
"test:mongodb:5.3.2": "npm run test:mongodb --dbversion=5.3.2",
127127
"test:mongodb:6.0.2": "npm run test:mongodb --dbversion=6.0.2",
128128
"test:mongodb:7.0.1": "npm run test:mongodb --dbversion=7.0.1",
129+
"test:mongodb:8.0.3": "npm run test:mongodb --dbversion=8.0.3",
129130
"test:postgres:testonly": "cross-env PARSE_SERVER_TEST_DB=postgres PARSE_SERVER_TEST_DATABASE_URI=postgres://postgres:password@localhost:5432/parse_server_postgres_adapter_test_database npm run testonly",
130131
"pretest": "cross-env MONGODB_VERSION=${MONGODB_VERSION:=5.3.2} MONGODB_TOPOLOGY=${MONGODB_TOPOLOGY:=standalone} mongodb-runner start -t ${MONGODB_TOPOLOGY} --version ${MONGODB_VERSION} -- --port 27017",
131132
"testonly": "cross-env MONGODB_VERSION=${MONGODB_VERSION:=5.3.2} MONGODB_TOPOLOGY=${MONGODB_TOPOLOGY:=standalone} TESTING=1 jasmine",

spec/ParseQuery.hint.spec.js

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ describe_only_db('mongo')('Parse.Query hint', () => {
2727
await TestUtils.destroyAllDataPermanently(false);
2828
});
2929

30-
it_only_mongodb_version('<5.1 || >=6')('query find with hint string', async () => {
30+
it_only_mongodb_version('<5.1 || >=6 <8')('query find with hint string', async () => {
3131
const object = new TestObject();
3232
await object.save();
3333

@@ -50,7 +50,19 @@ describe_only_db('mongo')('Parse.Query hint', () => {
5050
expect(explain.queryPlanner.winningPlan.queryPlan.inputStage.indexName).toBe('_id_');
5151
});
5252

53-
it_only_mongodb_version('<5.1 || >=6')('query find with hint object', async () => {
53+
it_only_mongodb_version('>=8')('query find with hint string', async () => {
54+
const object = new TestObject();
55+
await object.save();
56+
57+
const collection = await config.database.adapter._adaptiveCollection('TestObject');
58+
let explain = await collection._rawFind({ _id: object.id }, { explain: true });
59+
expect(explain.queryPlanner.winningPlan.stage).toBe('EXPRESS_IXSCAN');
60+
explain = await collection._rawFind({ _id: object.id }, { hint: '_id_', explain: true });
61+
expect(explain.queryPlanner.winningPlan.stage).toBe('FETCH');
62+
expect(explain.queryPlanner.winningPlan.inputStage.indexName).toBe('_id_');
63+
});
64+
65+
it_only_mongodb_version('<5.1 || >=6 <8')('query find with hint object', async () => {
5466
const object = new TestObject();
5567
await object.save();
5668

@@ -78,6 +90,20 @@ describe_only_db('mongo')('Parse.Query hint', () => {
7890
expect(explain.queryPlanner.winningPlan.queryPlan.inputStage.keyPattern).toEqual({ _id: 1 });
7991
});
8092

93+
it_only_mongodb_version('>=8')('query find with hint object', async () => {
94+
const object = new TestObject();
95+
await object.save();
96+
97+
const collection = await config.database.adapter._adaptiveCollection('TestObject');
98+
let explain = await collection._rawFind({ _id: object.id }, { explain: true });
99+
expect(explain.queryPlanner.winningPlan.stage).toBe('EXPRESS_IXSCAN');
100+
explain = await collection._rawFind({ _id: object.id }, { hint: { _id: 1 }, explain: true });
101+
expect(explain.queryPlanner.winningPlan.stage).toBe('FETCH');
102+
expect(explain.queryPlanner.winningPlan.inputStage.keyPattern).toEqual({
103+
_id: 1,
104+
});
105+
});
106+
81107
it_only_mongodb_version('<4.4')('query aggregate with hint string', async () => {
82108
const object = new TestObject({ foo: 'bar' });
83109
await object.save();

0 commit comments

Comments
 (0)