[SERVER-7508] conflicting mods not always detected, update implementation can create a doc with dup field names if not detected Created: 30/Oct/12  Updated: 10/Dec/14  Resolved: 27/Jul/13

Status: Closed
Project: Core Server
Component/s: Write Ops
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Aaron Staple Assignee: Unassigned
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
related to SERVER-6399 Refactor update() code Closed
Operating System: ALL
Participants:

 Description   

The code for detecting conflicting mods does not always detect conflicting mods. In cases where conflicting mods are not detected, the update implementation does not handle the conflicting mods properly and can create a document with duplicate field names.

Test

c = db.c;
c.drop();
 
c.save( {} );
 
// This triggers an error.                                                                 
c.update( {}, { $set:{ 'a.b':2, 'a.b.c':3 } } );
printjson( db.getLastError() );
 
// This generates { a:{ a:1, b:2, b:2 } }.                                                        
c.update( {}, { $set:{ 'a.a':1, 'a.b':2, 'a.b.c':3 } } );
printjson( db.getLastError() );
printjson( c.find().toArray() );

See ModSet::haveConflictingMod().



 Comments   
Comment by Scott Hernandez (Inactive) [ 27/Jul/13 ]

Resolved with refactoring: SERVER-6399

Now generates an error.

> // This generates { a:{ a:1, b:2, b:2 } }.                                                        
> c.update( {}, { $set:{ 'a.a':1, 'a.b':2, 'a.b.c':3 } } );
cannot use the part (b of a.b.c) to traverse the element ({b: 2.0})
> printjson( db.getLastError() );
"cannot use the part (b of a.b.c) to traverse the element ({b: 2.0})"
> printjson( c.find().toArray() );
[ { "_id" : ObjectId("51f3c4ca0ff54cf4a86d9110") } ]

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