Skip to content

Commit

Permalink
fix: properly handle err messages in MongoDB 2.6 servers
Browse files Browse the repository at this point in the history
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
  • Loading branch information
mbroadst committed Jan 19, 2020
1 parent 57f158f commit 0f4ab38
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions lib/cmap/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,14 +243,16 @@ function messageHandler(conn) {
conn.emit('clusterTimeReceived', document.$clusterTime);
}

if (document.writeConcernError) {
callback(new MongoWriteConcernError(document.writeConcernError, document));
return;
}
if (operationDescription.command) {
if (document.writeConcernError) {
callback(new MongoWriteConcernError(document.writeConcernError, document));
return;
}

if (document.ok === 0 || document.$err || document.errmsg || document.code) {
callback(new MongoError(document));
return;
if (document.ok === 0 || document.$err || document.errmsg || document.code) {
callback(new MongoError(document));
return;
}
}
}

Expand Down Expand Up @@ -290,6 +292,7 @@ function write(command, options, callback) {
fullResult: typeof options.fullResult === 'boolean' ? options.fullResult : false,
noResponse: typeof options.noResponse === 'boolean' ? options.noResponse : false,
documentsReturnedIn: options.documentsReturnedIn,
command: !!options.command,

// for BSON parsing
promoteLongs: typeof options.promoteLongs === 'boolean' ? options.promoteLongs : true,
Expand Down

0 comments on commit 0f4ab38

Please sign in to comment.