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

Suppressing output of '_id' from findAndModify causes exception.

    • Type: Icon: Bug Bug
    • Resolution: Duplicate
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 1.8.1, 1.9.0
    • Component/s: None
    • None
    • Environment:
      Reproduced in Win32 and Linux x86_64 but likely all.
    • ALL

      Repro steps in the mongo shell:

      > use benchmark
      switched to db benchmark
      > col = db.scoreboard
      benchmark.scoreboard
      > col.ensureIndex(

      {'user': 0}

      )
      > col.ensureIndex(

      {'score': 0}

      )
      > col.insert(

      {'user': 'bob', 'score': 5}

      )
      > db.runCommand({'findAndModify': 'scoreboard', 'query': {'user': 'bob', 'score': {'$lt': 10}}, 'update': {'$set': {'score': 10}}, 'upsert': true, 'fields': {'_id': false, 'score': true}})
      {
      "errmsg" : "exception: assertion db/../bson/bsonobjbuilder.h:115",
      "code" : 0,
      "ok" : 0
      }

      If you don't include '_id' in fields or set it to true there is no issue:
      > db.runCommand({'findAndModify': 'scoreboard', 'query': {'user': 'bob', 'score': {'$lt': 10}}, 'update': {'$set': {'score': 10}}, 'upsert': true, 'fields': {'score': true}})
      {
      "lastErrorObject" :

      { "updatedExisting" : true, "n" : 1, "connectionId" : 4278, "err" : null, "ok" : 1 }

      ,
      "value" :

      { "_id" : ObjectId("4dc2d279c545b10a39a72baf"), "score" : 5 }

      ,
      "ok" : 1
      }

      > db.runCommand({'findAndModify': 'scoreboard', 'query': {'user': 'bob', 'score': {'$lt': 10}}, 'update': {'$set': {'score': 10}}, 'upsert': true, 'fields': {'_id': true, 'score': true}})
      {
      "lastErrorObject" :

      { "updatedExisting" : false, "upserted" : ObjectId("4dc2d48d86d1f96e925acb8e"), "n" : 1, "connectionId" : 4278, "err" : null, "ok" : 1 }

      ,
      "value" : {

      },
      "ok" : 1

            Assignee:
            mathias@mongodb.com Mathias Stearn
            Reporter:
            bernie@mongodb.com Bernie Hackett
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: