[SERVER-12598] Cannot upsert 16MB document from shell Created: 04/Feb/14  Updated: 06/Feb/18  Resolved: 06/Feb/18

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

Type: Bug Priority: Minor - P4
Reporter: A. Jesse Jiryu Davis Assignee: DO NOT USE - Backlog - Platform Team
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
is related to SERVER-12305 Allow command request and response BS... Backlog
Operating System: ALL
Participants:

 Description   

Using the MongoDB 2.4.8 shell and OP_UPDATE, I can create a nearly-16MB document by upserting:

> var sixteen = '';
> while (sixteen.length < (16 * 1024 * 1024 - 30)) { var x = (sixteen += 'a'); }
> sixteen.length
16777186
> db.collection.update({key: 1}, {$set: {x: sixteen}}, true)
>

But in nightly shell build bffe6421 with the 'update' command, this fails:

> sixteen.length
16777186
> db.collection.update({key: 1}, {$set: {x: sixteen}}, true)
2014-02-04T09:52:35.515-0500 Error: Converting from JavaScript to BSON failed: Object size 16777256 exceeds limit of 16777216 bytes. at src/mongo/shell/batch_api.js:347



 Comments   
Comment by Asya Kamsky [ 06/Feb/18 ]

I think this is not a bug. With automatically added _id the document this test attempts to insert is greater than 16 MBs. Old server may have allowed it (and we still allow it in some scenarios i.e. SERVER-8694) but I believe current behavior here is correct (using same 'sixteen'):

var doc1={key:1, x:sixteen}
test@127.0.0.1:27017(3.6.0) > Object.bsonsize(doc1)
16777212  // should not succeed once _id is added to it
test@127.0.0.1:27017(3.6.0) > var doc2={_id:new ObjectId(), key:1, x:sixteen}
test@127.0.0.1:27017(3.6.0) > Object.bsonsize(doc2)
16777229   // *should* fail
test@127.0.0.1:27017(3.6.0) > var doc3={_id:new ObjectId(), x:sixteen}
test@127.0.0.1:27017(3.6.0) > Object.bsonsize(doc3)
16777216   // should succeed
test@127.0.0.1:27017(3.6.0) > db.collection.update({_id:new ObjectId()}, {$set: {x: sixteen}}, true)
WriteResult({
	"nMatched" : 0,
	"nUpserted" : 1,
	"nModified" : 0,
	"_id" : ObjectId("5a79f3f1841826511293bc89")
})
test@127.0.0.1:27017(3.6.0) > var doc5=db.collection.findOne()
test@127.0.0.1:27017(3.6.0) > Object.bsonsize(doc5)
16777216

I'm going to close as works correctly. Please reopen if my analysis is incorrect.

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