Skip to content

Commit 0f4ab38

Browse files
committed
fix: properly handle err messages in MongoDB 2.6 servers
In server versions where we cannot assume we are always working with commands, we need to encode the knowledge that we are running a command to inform how we process the response
1 parent 57f158f commit 0f4ab38

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

lib/cmap/connection.js

+10-7
Original file line numberDiff line numberDiff line change
@@ -243,14 +243,16 @@ function messageHandler(conn) {
243243
conn.emit('clusterTimeReceived', document.$clusterTime);
244244
}
245245

246-
if (document.writeConcernError) {
247-
callback(new MongoWriteConcernError(document.writeConcernError, document));
248-
return;
249-
}
246+
if (operationDescription.command) {
247+
if (document.writeConcernError) {
248+
callback(new MongoWriteConcernError(document.writeConcernError, document));
249+
return;
250+
}
250251

251-
if (document.ok === 0 || document.$err || document.errmsg || document.code) {
252-
callback(new MongoError(document));
253-
return;
252+
if (document.ok === 0 || document.$err || document.errmsg || document.code) {
253+
callback(new MongoError(document));
254+
return;
255+
}
254256
}
255257
}
256258

@@ -290,6 +292,7 @@ function write(command, options, callback) {
290292
fullResult: typeof options.fullResult === 'boolean' ? options.fullResult : false,
291293
noResponse: typeof options.noResponse === 'boolean' ? options.noResponse : false,
292294
documentsReturnedIn: options.documentsReturnedIn,
295+
command: !!options.command,
293296

294297
// for BSON parsing
295298
promoteLongs: typeof options.promoteLongs === 'boolean' ? options.promoteLongs : true,

0 commit comments

Comments
 (0)