I thought I'd follow up here on - since it may be interesting for a wider audience. I'll add a backref to the github issue
I'm still not totally clear on this - so I'm hoping you can clarify it for me. The problem in a nutshell: when I upgraded to the latest mongoose (3.5.1 I think), my tests started failing on a re-run with OverwriteModelError (i.e. using mocha's --watch option
http://visionmedia.github.com/mocha/#watch-option) -- first pass through on the tests passes.
This is caused by a programming error. Calling either mongoose.model()
or connection.model()
with the same name and schema multiple times does not result in an error. Passing the name of a model that exists with a different schema produces the error. Overwriting models was never actually permitted.
If mocha watch re-requires your schema and calls mongoose.model(preExistingName, newSchema)
then yes you'll get an error now. Previously in this scenario, mongoose wasn't compiling a new model at all, it would just swallow the programming error and return the old model, which is wrong behavior.
I've done some poking around to see how other people are setting up testing with mongoose + mocha, and it is all the same pattern. They require('mongoose') at the top of the test, and do mongoose.connect('mongodb://localhost/test') as a direct expression, or as part of before( ) / after ( ) -- but this pattern doesn't seem to work anymore with this new enforcement of OverwriteModelError
So, I'm taking a look at your internal mongoosejs source tests (as you referenced in the github issue) to see how you do your own tests, and see if I can create a workaround, but I'm still confused as to why this occurs, since I'm not trying to create the model multiple times with a different schema.
Anyone else running into this with the latest release?