From 0f4ab38ac4d7c51f812ee7359e1d255f967d8d67 Mon Sep 17 00:00:00 2001 From: Matt Broadstone Date: Sun, 19 Jan 2020 11:16:05 -0500 Subject: [PATCH] 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 --- lib/cmap/connection.js | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/lib/cmap/connection.js b/lib/cmap/connection.js index a93d848903f..8f0cd4df71a 100644 --- a/lib/cmap/connection.js +++ b/lib/cmap/connection.js @@ -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; + } } } @@ -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,