2. Me = Scott Hernandez
● Worked on Morphia (+java), community
● Over 3 years with MongoDB
● Worked on update re-write in 2.6
● Working on replication team now
● Lots of experience with many parts
3. User Components
update({f:1}, {$set: {a: 2}}, {multi:true})
● Query
● Update Modifiers (or replacement doc)
● Options
o multi, upsert
o writeConcern
4. New Code (in 2.6)
● New update and query code
● Replaced all modifier implementations
● New validation and error messages
● Using new “MutableBSON” document class
● New oplog entry generation code
12. Modifier::prepare
● Work with doc, but don’t change it
● Validate field, type, operation
● Substitute positional path element, if appl.
● Do work, stored to the side
● Return ExecInfo (no-op, fields affected)
21. New Modifiers
● Mul(tiply) existing field by constant: $mul
{a:1} + {$mul:{a:10}} -> {a:10}
● Min/Max of existing field w/constant: $min/$max
{a:1} + {$min:{a:100}} -> {a:1} (no-op)
● Store current date/ts in a field: $currentDate
{} + {$currentDate:{ dt: true}} -> {dt: new Date()}
22. Improvements
● $push
o $sort elements (works with numbers/strings/etc)
o $sort and/or $slice (doesn’t require $sort for $slice)
o $slice off either end (no middle yet)
o $position lets you specify where in the array
o $each, $sort, $slice no longer order dep.
● $bit
o xor support
23. Improvements
● Error messages with context
o The field 'l' must be an array but is of type
NumberLong in document {_id:
ObjectId('52a0a61672a5f2f771099b54')}
o Cannot apply $inc to a value of non-integral type.
{_id: ObjectId('52a0a61672a5f2f771099b54')} has
the field 'd' of non-integral type Date
24. Improvements
● No reordering of fields (except: _id is first)
● Better building of doc during insert
o update({a:1, b:1}, {$inc:{c:1}}, 0,1) -> {a:1, b:1, c:1}
o now uses parsed query tree to get equalities
● Will now return new _id for all types
● Accurate tracking of no-ops, modified docs
25. Improvements
● Validation
o Immutable Fields (_id, shard keys)
o Storage restrictions (no $field, “.”, _id field types)
o DBRef validation
● Can now query + set _id/shard-key fields
o update({_id:1}, {$set:{_id:1, ...}}) // ok
o update({_id:1}, {_id:2, ...}) // error
● Cleanup bad data ($unset/$rename etc)