Skip to content

fix: Explain queries should always return as an array of results #1375

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: alpha
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion integration/test/ParseQueryTest.js
Original file line number Diff line number Diff line change
@@ -2361,13 +2361,16 @@ describe('Parse Query', () => {
const explain = await query.find();
let indexName = '';
// https://www.mongodb.com/docs/manual/reference/explain-results/#std-label-queryPlanner
const plan = explain.queryPlanner.winningPlan;
const plan = explain[0].queryPlanner.winningPlan;
if (plan.inputStage) {
indexName = plan.inputStage.inputStage.indexName;
} else {
indexName = plan.queryPlan.inputStage.inputStage.indexName;
}
assert.equal(indexName, '_id_');

const explainFirst = await query.first();
assert.equal(explainFirst.queryPlanner.winningPlan.inputStage.inputStage.indexName, '_id_');
});

it('can query with select on null field', async () => {
4 changes: 4 additions & 0 deletions src/ParseQuery.js
Original file line number Diff line number Diff line change
@@ -896,6 +896,10 @@ class ParseQuery {
if (!objects[0]) {
return undefined;
}
// Return generic object when explain is used
if (this._explain) {
return objects[0];
}
if (!objects[0].className) {
objects[0].className = this.className;
}
8 changes: 8 additions & 0 deletions src/__tests__/ParseQuery-test.js
Original file line number Diff line number Diff line change
@@ -1319,6 +1319,14 @@ describe('ParseQuery', () => {
q.explain();
q.equalTo('size', 'small')
.find()
.then(results => {
expect(results[0].objectId).toBe('I1');
expect(results[0].size).toBe('small');
expect(results[0].name).toEqual('Product 3');
done();
});
q.equalTo('size', 'small')
.first()
.then(result => {
expect(result.objectId).toBe('I1');
expect(result.size).toBe('small');