From f91304ba0a2c7848e878cb1c99d409b6e0078f53 Mon Sep 17 00:00:00 2001 From: Matt Broadstone Date: Mon, 11 Feb 2019 13:58:05 -0500 Subject: [PATCH] fix(msg): support raw cursor results using OP_MSG --- lib/connection/msg.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/connection/msg.js b/lib/connection/msg.js index 699298adc..acc6e89d5 100644 --- a/lib/connection/msg.js +++ b/lib/connection/msg.js @@ -209,6 +209,7 @@ class BinMsg { this.index = 4; // Allow the return of raw documents instead of parsing const raw = options.raw || false; + const documentsReturnedIn = options.documentsReturnedIn || null; const promoteLongs = typeof options.promoteLongs === 'boolean' ? options.promoteLongs : this.opts.promoteLongs; const promoteValues = @@ -238,6 +239,14 @@ class BinMsg { } } + // TODO: This is special-cased in the OP_RESPONSE code, but should probably + // be moved into Cursor logic. + if (this.documents.length === 1 && documentsReturnedIn != null && raw) { + _options.fieldsAsRaw = { [documentsReturnedIn]: true }; + const doc = this.bson.deserialize(this.documents[0], _options); + this.documents = [doc]; + } + this.parsed = true; } }