API: very rudimentary implementation of _v. We'll have a proper

implementation in APIv2, but this will help with performance for rewrite
& mobile
This commit is contained in:
Tyler Renelle
2013-08-28 17:21:36 -04:00
parent 13a4aadfb4
commit 72a26d35bb
3 changed files with 16 additions and 7 deletions
+5 -1
View File
@@ -6,9 +6,12 @@ _ = require('lodash')
UserSchema = new Schema(
_id: {type: String, 'default': helpers.uuid}
apiToken: {type: String, 'default': helpers.uuid}
# We want to know *every* time an object updates. Mongoose uses __v to designate when an object contains arrays which
# have been updated (http://goo.gl/gQLz41), but we want *every* update
_v: {type: Number, 'default': 0}
achievements:
originalUser: Boolean
helpedHabit: Boolean
@@ -181,6 +184,7 @@ UserSchema.methods.toJSON = () ->
# Custom setter/getter virtuals?
UserSchema.pre 'save', (next) ->
@markModified('tasks')
@._v++ #our own version incrementer
next()
module.exports.schema = UserSchema