saintedlama/mongoose-version — pull request #17 by alanshaw (2014-11-19 09:00:22+00:00)
Title: Fix bug with collection strategy

When using the collection strategy a single version can be inserted, but the second, and subsequent versions fail to be saved to the collection.

This failure is silent, unless you enable debug mode. The error is a unique key constraint violation and occurs because you can't [delete the `_id` property from a mongoose model](https://github.com/saintedlama/mongoose-version/blob/e43ac7c25dcd788d2edbd5bdcce44eb0e6790a7c/lib/strategies/collection.js#L29). The first version gets the `_id` of the origin document, and the second (and subsequent) documents get the same ID.

I don't know if this is a new thing in mongoose, but the test I created definitely fails when run against the old collection strategy code when using the version of mongoose specified in the `package.json`. The fix is to clone the raw document and delete the `_id` field from a vanilla js object before creating a mongoose model based on it.