mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-05-29 12:01:32 +02:00
change mongomangers upsert to use an inc
this is tested and does work with new documents
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
|
||||
@@ -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()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user