mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
change mongomangers upsert to use an inc
this is tested and does work with new documents
This commit is contained in:
parent
7242119532
commit
a73dc90b00
2 changed files with 3 additions and 2 deletions
|
@ -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()
|
||||
|
||||
|
|
Loading…
Reference in a new issue