Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-42741

getting back both _id of modified documents and writeResult information

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Open
    • Priority: Major - P3
    • Resolution: Unresolved
    • Affects Version/s: 4.0.12, 4.2.0
    • Fix Version/s: Backlog
    • Component/s: Shell, Usability
    • Labels:
      None

      Description

      For many years I've fought with mongodb when I want to perform an upsert operation that both:
       
      1) returns nModified/nUpserted/etc. result (e.g. https://docs.mongodb.com/manual/reference/method/WriteResult/)
      2) returns the id(s) of any modified records. (unfortunately, only an upsert returns WriteResult._id). Returning the fully modified document is even better, but usually my use cases would be sufficient with returning the _id
       
      For example,
       
       

      db.test.insert({fruit: 'apple'});
      db.test.insert({fruit: 'banana'});
      db.test.insert({fruit: 'pear'});

       
       

      db.test.update({fruit: 'orange'}, {$set: {fruit: 'grape'}}, {upsert: true});

      will give me nUpserted 1, and _id because the operation resulted in an upsert.
       

      db.test.update({fruit: 'apple'}, {$set: {fruit: 'grape'}}, {upsert: true});

      will give me nModified 1, but no _id because the operation was not an upsert.
       
      db.test.findAndModify() returns the record (either old or new as defined by the option), but no WriteResult information so it is not possible to determine if nModified happened or not.
       
      I increasingly find reasons when writing code to want to get this type of information back in one operation.
       
       
       

        Attachments

          Issue Links

            Activity

              People

              • Votes:
                0 Vote for this issue
                Watchers:
                7 Start watching this issue

                Dates

                • Created:
                  Updated: