Uploaded image for project: 'Node.js Driver'
  1. Node.js Driver
  2. NODE-175

Errors are not returned when 'raw' option is set to true

    • Type: Icon: Bug Bug
    • Resolution: Won't Fix
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 1.3, 1.4
    • Component/s: None
    • Labels:

      The node driver seems to rely on the contents of the object returned from the server in order to determine whether or not the object is an error (for example, https://github.com/mongodb/node-mongodb-native/blob/1.4/lib/mongodb/cursor.js#L688). Since the 'raw' option causes BSON buffers to be returned rather than deserialized objects, their contents cannot be inspected.

      This causes server errors to be returned as normal documents to the application that is using the driver, and thus requires the application itself to re-implement error-detection logic similar to the one employed in the driver. This poses a particular annoyance if the application is attempting to stream results directly from the driver to the client, as it would require always inspecting the first element of the stream to make sure it does not contain an error.

      However, the raw response from the server actual contains a responseFlag field that, according to documentation, will be set to 2 if an error has occurred during the execution of the query (as seen at http://docs.mongodb.org/meta-driver/latest/legacy/mongodb-wire-protocol/#op-reply).

      I believe this issue can be fixed by implementing something similar to the following, in the function referenced above in cursor.js:

      if(self.raw && result.responseFlag == 2 && result.documents != null && result.documents.length == 1) return callback(result.documents[0], null);

            Assignee:
            christkv Christian Amor Kvalheim
            Reporter:
            gal@kinvey.com Gal Niv
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: