diff --git a/integration/test/ParseQueryTest.js b/integration/test/ParseQueryTest.js index 5da39bba2..4dfd758f8 100644 --- a/integration/test/ParseQueryTest.js +++ b/integration/test/ParseQueryTest.js @@ -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 () => { diff --git a/src/ParseQuery.js b/src/ParseQuery.js index f2e18b4d0..bff313767 100644 --- a/src/ParseQuery.js +++ b/src/ParseQuery.js @@ -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; } diff --git a/src/__tests__/ParseQuery-test.js b/src/__tests__/ParseQuery-test.js index 4499b27fa..f70093028 100644 --- a/src/__tests__/ParseQuery-test.js +++ b/src/__tests__/ParseQuery-test.js @@ -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');