LearnBoost/mongoose — pull request #836 by boutell (2012-04-14 19:58:28+00:00)
Title: If an insert (not an update) fails, reset isNew so that there is a second chance to save the object

Right now if an insert fails you are stuck because the isNew flag is never set to true again. With this simple patch this issue goes away. Please see the test program in this gist, which verifies that I didn't break update() in the process of fixing this issue. (:

https://gist.github.com/2387479

This allows things like generating a more unique slug on the basis of a unique index error in a truly concurrency-safe way.