$__.activePaths is reseted after a failed save()

27 views
Skip to first unread message

Guilherme Souza

unread,
Nov 30, 2014, 8:04:21 AM11/30/14
to mongoo...@googlegroups.com
Hi,

This is my first post to this list, sorry if this has already been discussed, but I haven't found it.

When I change a path in a document and save it, if the save operation fails (due to a duplicate key, for example), the path I've modified is now not marked as modified anymore.
This implies that if I try to save again, that path won't be updated and now I have a inconsistent document in memory.

Example:
// Now we're going to finalize order2
// We choose a random code for it
order2
.isFinalized = true
order2
.code = code
order2
.save(function (err) {
   
// Unfortunately the code is taken (duplicate key error)
   
assert(err)
   
assert(err.code === 11001 || err.code === 11000)

   
// No problem, pick another code and try again
    order2
.code = code2
    order2
.save(function (err) {
       
// This time it's fine
       
assert.ifError(err)

       
// Now if we check the DB...
       
Order.findById(order2, function (err, order2InDB) {
           
assert.ifError(err)

           
// save() hasn't saved the isFinalized path
           
assert(order2.isFinalized)
           
assert(order2InDB.isFinalized) // this will throw
       
})
   
})
})

Full code: https://gist.github.com/sitegui/dbcbca491cbf91a10ed0

I don't know whether this is intended behavior or an actual bug. Can someone confirm this?

Thank you for the support.

jondavidjohn

unread,
Dec 4, 2014, 4:50:22 PM12/4/14
to mongoo...@googlegroups.com
This pull request just got merged into master to fix this issue.

Reply all
Reply to author
Forward
0 new messages