Skip to content

Commit a68a164

Browse files
committed
handle explain for legacy servers
1 parent 207e774 commit a68a164

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

src/operations/aggregate.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ export class AggregateOperation<T = Document> extends CommandOperation<Aggregate
6666
}
6767

6868
if (this.explain && this.writeConcern) {
69-
console.dir({ writeConcern: this.writeConcern });
7069
throw new MongoError('"explain" cannot be used on an aggregate call with writeConcern');
7170
}
7271

src/operations/find.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,17 @@ export class FindOperation extends CommandOperation<FindOptions, Document> {
239239
this.ns.toString(),
240240
findCommand,
241241
{ fullResult: !!this.fullResponse, ...this.options, ...this.bsonOptions },
242-
callback
242+
(err, result) => {
243+
if (err) return callback(err);
244+
if (this.explain) {
245+
// TODO: NODE-2900
246+
if (result.documents && result.documents[0]) {
247+
return callback(undefined, result.documents[0]);
248+
}
249+
}
250+
251+
callback(undefined, result);
252+
}
243253
);
244254
}
245255
}

0 commit comments

Comments
 (0)