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

Detect writeConcernError from findAndModify() shell helper

    • Type: Icon: Improvement Improvement
    • Resolution: Won't Fix
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 3.2.0
    • Component/s: JavaScript, Shell
    • Labels:
    • Server Tooling & Methods

      When using the shell helper db.collection.findAndModify(), you cannot determine if a write concern error has occurred. You can only do so via the dbcommand version of findAndModify:

      replset:PRIMARY> db.products.find()
      { "_id" : ObjectId("568eb38f3a04b65e35ff642c"), "sku" : 1, "field" : 9 }
      replset:PRIMARY> db.runCommand( { findAndModify: "products", query: { sku: 1 }, update: { $inc: { field: 1 } }, writeConcern: { w: 3, wtimeout: 5000 } } )
      {
              "lastErrorObject" : {
                      "updatedExisting" : true,
                      "n" : 1
              },
              "value" : {
                      "_id" : ObjectId("568eb38f3a04b65e35ff642c"),
                      "sku" : 1,
                      "field" : 9
              },
              "writeConcernError" : {
                      "code" : 64,
                      "errmsg" : "waiting for replication timed out"
              },
              "ok" : 1
      }
      replset:PRIMARY> db.products.findAndModify( { query: { sku: 1 }, update: { $inc: { field: 1 } }, writeConcern: { w: 3, wtimeout: 5000 } } )
      { "_id" : ObjectId("568eb38f3a04b65e35ff642c"), "sku" : 1, "field" : 10 }
      

            Assignee:
            backlog-server-stm Backlog - Server Tooling and Methods (STM) (Inactive)
            Reporter:
            kyle.suarez@mongodb.com Kyle Suarez
            Votes:
            0 Vote for this issue
            Watchers:
            10 Start watching this issue

              Created:
              Updated:
              Resolved: