[SERVER-71197] Restore the detailed JSON return document the getLastError used to return Created: 09/Nov/22  Updated: 28/Nov/22  Resolved: 28/Nov/22

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: 6.0.2
Fix Version/s: None

Type: Improvement Priority: Major - P3
Reporter: William Byrne III Assignee: David Storch
Resolution: Won't Do Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Sprint: QE 2022-11-28, QE 2022-12-12
Participants:
Case:

 Description   

Prior to version 5.1, getLastError, db.getLastError(), or db.getLastErrorObj() could be used to get detailed information about the success or failure of write operations:

  mongo << host/port/user etc >> --quiet 
        --eval "db.ValidProducts.drop();printjson(db.runCommand( { getLastError: 1 } ));"

  {
    "connectionId" : 2869,
    "n" : 0,
    "syncMillis" : 0,
    "writtenTo" : null,
    "err" : null,
    "ok" : 1

{\{  }

}}

In MongoDB version 6.0, getLastError was removed and write commands often only return a boolean, instead of the detailed JSON output:

  mongosh << host/port/user etc >> --quiet 
          --eval "var drc = db.ValidProducts.drop(); printjson(drc)"
  false

 

This request is to restore the ability to get more detailed return documents from write operations.



 Comments   
Comment by David Storch [ 28/Nov/22 ]

Given the lack of information about the exact behavior requested by this ticket, I am closing it as "Won't Do". See my previous comment for a more detailed description of why we removed support for the getLastError command and what information we need in order to take action on this request. Please feel free to provide additional information about your use case or requirements, in which case we would be happy to re-open and re-triage this ticket!

Comment by David Storch [ 15/Nov/22 ]

Hi william.byrne@mongodb.com! In order to act on this ticket, I think we need more information regarding what information exactly you would like to receive in response to a write operation. Your example involves a collection drop. Bypassing the legacy mongo shell helpers and running the command directly, the response to the command looks like this:

MongoDB Enterprise > db.runCommand({drop: "c"})
{ "nIndexesWas" : 3, "ns" : "test.c", "ok" : 1 }

That's what the OP_MSG reply payload sent from the server to the shell actually looks like; no other information about the result of the drop command is actually returned to the client. Can you tell me more about your use case? What were you using getLastError for that you can no longer achieve, or what specific information do you want to be returned and by what commands?

As a postscript, I'd like to add that I don't see us ever restoring the actual getLastError command or the corresponding shell helpers. The getLastError command was designed to be used by drivers in connection with the legacy op codes for doing writes (OP_INSERT, OP_UPDATE, and OP_DELETE). When we removed support for these legacy op codes, it meant that supported drivers no longer needed to run getLastError commands. This enabled us to delete the code implementing the getLastError command and its underlying infrastructure, which was an important elimination of tech debt to simplify our code base.

Generated at Thu Feb 08 06:18:19 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.