[SERVER-3050] Suppressing output of '_id' from findAndModify causes exception. Created: 05/May/11  Updated: 29/Aug/11  Resolved: 09/May/11

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: 1.8.1, 1.9.0
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Bernie Hackett Assignee: Mathias Stearn
Resolution: Duplicate Votes: 1
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Reproduced in Win32 and Linux x86_64 but likely all.


Issue Links:
Duplicate
duplicates SERVER-2626 Excluding _id field doesn't work with... Closed
Operating System: ALL
Participants:

 Description   

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


Generated at Thu Feb 08 03:01:56 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.