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

insertOneWriteOpResult generates incorrect string when passed to JSON.stringify

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 3.2.4
    • Affects Version/s: 3.2.3
    • Component/s: None

      I'm executing a simple insertOne (using the Promise version of the API) and looking at the result object with JSON.stringify(), but instead of an object with 5 properties (insertedCount, ops, insertedId, connection, result as specified here), I'm seeing an object with only 2 properties (ok, n). Those two are the properties of "insertOneWriteOpResult.result", but why is JSON.stringify only displaying that sub-property instead of the full object? It causes confusion when using the insertOneWriteOpResult object.

      const client = await MongoClient.connect(my_connection_string);
      return client.db('my-db').collection('my-collection')
          .insertOne(myDoc)
          .then(resultObject => {
      
               // The following line prints {"n":1,"ok":1}
               console.log(JSON.stringify(resultObject));
      
               // But the following line prints undefined
               console.log(resultObject.ok);
      
               // And this one correctly prints 1
               console.log(resultObject.result.ok);
           });

            Assignee:
            katherine.walker@mongodb.com Katherine Walker (Inactive)
            Reporter:
            alexvy86 Alejandro Villarreal
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: