Modified the code for latest version of Mongoose.
Added tests to todo.