Skip to content

Commit cb38f31

Browse files
committed
Update index tests to pass against mongo 8.
1 parent a6f2414 commit cb38f31

File tree

2 files changed

+46
-18
lines changed

2 files changed

+46
-18
lines changed

test/mocha/30-batchVersions.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*!
2-
* Copyright (c) 2020-2022 Digital Bazaar, Inc. All rights reserved.
2+
* Copyright (c) 2020-2025 Digital Bazaar, Inc. All rights reserved.
33
*/
44
import {cleanDB, insertRecord, isBatchVersion} from './helpers.js';
55
import {
@@ -221,10 +221,17 @@ describe('BatchVersions Database Tests', function() {
221221
executionStats.nReturned.should.equal(1);
222222
executionStats.totalKeysExamined.should.equal(1);
223223
executionStats.totalDocsExamined.should.equal(1);
224-
executionStats.executionStages.inputStage.inputStage.stage
225-
.should.equal('IXSCAN');
226-
executionStats.executionStages.inputStage.inputStage.keyPattern
227-
.should.eql({'batchVersionOptions.id': 1});
224+
const {executionStages: targetStage} = executionStats;
225+
// only mongodb 8+ has 'EXPRESS_IXSCAN'
226+
if(targetStage.stage === 'EXPRESS_IXSCAN') {
227+
targetStage.keyPattern.should.eql(
228+
'{ batchVersionOptions.id: 1 }');
229+
} else {
230+
targetStage = executionStages.inputStage.inputStage;
231+
targetStage.stage.should.equal('IXSCAN');
232+
targetStage.keyPattern.should.eql(
233+
{'batchVersionOptions.id': 1});
234+
}
228235
});
229236
it(`is properly indexed for 'batchVersionOptions.id' in getOptions()`,
230237
async function() {

test/mocha/40-entities.js

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*!
2-
* Copyright (c) 2020-2023 Digital Bazaar, Inc. All rights reserved.
2+
* Copyright (c) 2020-2025 Digital Bazaar, Inc. All rights reserved.
33
*/
44
import {cleanDB, insertRecord} from './helpers.js';
55
import {mockEntity1, mockEntity2, mockEntity3} from './mock.data.js';
@@ -53,10 +53,17 @@ describe('Entities Database Tests', function() {
5353
executionStats.nReturned.should.equal(1);
5454
executionStats.totalKeysExamined.should.equal(1);
5555
executionStats.totalDocsExamined.should.equal(1);
56-
executionStats.executionStages.inputStage.inputStage.stage
57-
.should.equal('IXSCAN');
58-
executionStats.executionStages.inputStage.inputStage.keyPattern
59-
.should.eql({'entity.internalId': 1});
56+
const {executionStages: targetStage} = executionStats;
57+
// only mongodb 8+ has 'EXPRESS_IXSCAN'
58+
if(targetStage.stage === 'EXPRESS_IXSCAN') {
59+
targetStage.keyPattern.should.eql(
60+
'{ entity.internalId: 1 }');
61+
} else {
62+
targetStage = executionStages.inputStage.inputStage;
63+
targetStage.stage.should.equal('IXSCAN');
64+
targetStage.keyPattern.should.eql(
65+
{'entity.internalId': 1});
66+
}
6067
});
6168
it(`is properly indexed for 'entity.internalId' and` +
6269
`'entity.batchInvalidationCount' in ` +
@@ -81,10 +88,17 @@ describe('Entities Database Tests', function() {
8188
executionStats.nReturned.should.equal(1);
8289
executionStats.totalKeysExamined.should.equal(1);
8390
executionStats.totalDocsExamined.should.equal(1);
84-
executionStats.executionStages.inputStage.inputStage.stage
85-
.should.equal('IXSCAN');
86-
executionStats.executionStages.inputStage.inputStage.keyPattern
87-
.should.eql({'entity.internalId': 1});
91+
const {executionStages: targetStage} = executionStats;
92+
// only mongodb 8+ has 'EXPRESS_IXSCAN'
93+
if(targetStage.stage === 'EXPRESS_IXSCAN') {
94+
targetStage.keyPattern.should.eql(
95+
'{ entity.internalId: 1 }');
96+
} else {
97+
targetStage = executionStages.inputStage.inputStage;
98+
targetStage.stage.should.equal('IXSCAN');
99+
targetStage.keyPattern.should.eql(
100+
{'entity.internalId': 1});
101+
}
88102
});
89103
it(`is properly indexed for 'entity.internalId' and ` +
90104
`'entity.batchInvalidationCount' in ` +
@@ -132,10 +146,17 @@ describe('Entities Database Tests', function() {
132146
executionStats.nReturned.should.equal(1);
133147
executionStats.totalKeysExamined.should.equal(1);
134148
executionStats.totalDocsExamined.should.equal(1);
135-
executionStats.executionStages.inputStage.inputStage.stage
136-
.should.equal('IXSCAN');
137-
executionStats.executionStages.inputStage.inputStage.keyPattern
138-
.should.eql({'entity.internalId': 1});
149+
const {executionStages: targetStage} = executionStats;
150+
// only mongodb 8+ has 'EXPRESS_IXSCAN'
151+
if(targetStage.stage === 'EXPRESS_IXSCAN') {
152+
targetStage.keyPattern.should.eql(
153+
'{ entity.internalId: 1 }');
154+
} else {
155+
targetStage = executionStages.inputStage.inputStage;
156+
targetStage.stage.should.equal('IXSCAN');
157+
targetStage.keyPattern.should.eql(
158+
{'entity.internalId': 1});
159+
}
139160
});
140161
});
141162
describe('getCount()', function() {

0 commit comments

Comments
 (0)