change mongomangers upsert to use an inc

this is tested and does work with new documents
This commit is contained in:
Henry Oswald 2015-02-26 16:01:10 +00:00
parent 7242119532
commit a73dc90b00
2 changed files with 3 additions and 2 deletions

View file

@ -12,9 +12,10 @@ module.exports = MongoManager =
upsertIntoDocCollection: (project_id, doc_id, lines, oldRev, callback)->
update =
$set:{}
$inc:{}
update.$set["lines"] = lines
update.$set["project_id"] = ObjectId(project_id)
update.$set["rev"] = oldRev + 1
update.$inc["rev"] = 1 #on new docs being created this will set the rev to 1
db.docs.update _id: ObjectId(doc_id), update, {upsert: true}, callback

View file

@ -61,7 +61,7 @@ describe "MongoManager", ->
args = @db.docs.update.args[0]
assert.deepEqual args[0], {_id: ObjectId(@doc_id)}
assert.equal args[1]["$set"]["lines"], @lines
assert.equal args[1]["$set"]["rev"], 78
assert.equal args[1]["$inc"]["rev"], 1
assert.deepEqual args[1]["$set"]["project_id"], ObjectId(@project_id)
done()