diff --git a/services/docstore/app/coffee/DocArchiveManager.coffee b/services/docstore/app/coffee/DocArchiveManager.coffee index 5e0272466c..345f751f2a 100644 --- a/services/docstore/app/coffee/DocArchiveManager.coffee +++ b/services/docstore/app/coffee/DocArchiveManager.coffee @@ -67,7 +67,7 @@ module.exports = DocArchive = if err? || res.statusCode != 200 logger.err err:err, res:res, project_id:project_id, doc_id:doc_id, "something went wrong unarchiving doc from aws" return callback new Errors.NotFoundError("Error in S3 request") - MongoManager.upsertIntoDocCollection project_id, doc_id.toString(), lines, (err) -> + MongoManager.upsertIntoDocCollection project_id, doc_id.toString(), {lines}, (err) -> return callback(err) if err? logger.log project_id: project_id, doc_id: doc_id, "deleting doc from s3" request.del options, (err, res, body)-> diff --git a/services/docstore/app/coffee/DocManager.coffee b/services/docstore/app/coffee/DocManager.coffee index 64b5b41522..09218ed5b8 100644 --- a/services/docstore/app/coffee/DocManager.coffee +++ b/services/docstore/app/coffee/DocManager.coffee @@ -67,7 +67,7 @@ module.exports = DocManager = oldVersion: doc?.version newVersion: version }, "updating doc lines" - MongoManager.upsertIntoDocCollection project_id, doc_id, lines, (error)-> + MongoManager.upsertIntoDocCollection project_id, doc_id, {lines}, (error)-> return callback(callback) if error? MongoManager.setDocVersion doc_id, version, (error) -> return callback(error) if error? diff --git a/services/docstore/app/coffee/MongoManager.coffee b/services/docstore/app/coffee/MongoManager.coffee index d1c941e788..73820dbd09 100644 --- a/services/docstore/app/coffee/MongoManager.coffee +++ b/services/docstore/app/coffee/MongoManager.coffee @@ -15,18 +15,16 @@ module.exports = MongoManager = inS3: true db.docs.find query, {}, callback - upsertIntoDocCollection: (project_id, doc_id, lines, callback)-> + upsertIntoDocCollection: (project_id, doc_id, updates, callback)-> update = - $set:{} - $inc:{} - $unset:{} - update.$set["lines"] = lines + $set: updates + $inc: + rev: 1 + $unset: + inS3: true update.$set["project_id"] = ObjectId(project_id) - update.$inc["rev"] = 1 #on new docs being created this will set the rev to 1 - update.$unset["inS3"] = true db.docs.update _id: ObjectId(doc_id), update, {upsert: true}, callback - markDocAsDeleted: (project_id, doc_id, callback)-> db.docs.update { _id: ObjectId(doc_id), diff --git a/services/docstore/test/unit/coffee/DocManagerTests.coffee b/services/docstore/test/unit/coffee/DocManagerTests.coffee index 676a7fbe02..95cda2b95c 100644 --- a/services/docstore/test/unit/coffee/DocManagerTests.coffee +++ b/services/docstore/test/unit/coffee/DocManagerTests.coffee @@ -179,7 +179,7 @@ describe "DocManager", -> it "should upsert the document to the doc collection", -> @MongoManager.upsertIntoDocCollection - .calledWith(@project_id, @doc_id, @newDocLines) + .calledWith(@project_id, @doc_id, {lines: @newDocLines}) .should.equal true it "should update the version", -> @@ -216,7 +216,7 @@ describe "DocManager", -> it "should upsert the document to the doc collection", -> @MongoManager.upsertIntoDocCollection - .calledWith(@project_id, @doc_id, @oldDocLines) + .calledWith(@project_id, @doc_id, {lines: @oldDocLines}) .should.equal true it "should update the version", -> @@ -272,7 +272,7 @@ describe "DocManager", -> it "should upsert the document to the doc collection", -> @MongoManager.upsertIntoDocCollection - .calledWith(@project_id, @doc_id, @doc.lines) + .calledWith(@project_id, @doc_id, {lines: @doc.lines}) .should.equal true describe "when the doc does not exist", -> @@ -282,7 +282,7 @@ describe "DocManager", -> it "should upsert the document to the doc collection", -> @MongoManager.upsertIntoDocCollection - .calledWith(@project_id, @doc_id, @newDocLines) + .calledWith(@project_id, @doc_id, {lines: @newDocLines}) .should.equal true it "should return the callback with the new rev", -> diff --git a/services/docstore/test/unit/coffee/MongoManagerTests.coffee b/services/docstore/test/unit/coffee/MongoManagerTests.coffee index cf1479a880..19a68c4d79 100644 --- a/services/docstore/test/unit/coffee/MongoManagerTests.coffee +++ b/services/docstore/test/unit/coffee/MongoManagerTests.coffee @@ -58,7 +58,7 @@ describe "MongoManager", -> @oldRev = 77 it "should upsert the document", (done)-> - @MongoManager.upsertIntoDocCollection @project_id, @doc_id, @lines, (err)=> + @MongoManager.upsertIntoDocCollection @project_id, @doc_id, {@lines}, (err)=> args = @db.docs.update.args[0] assert.deepEqual args[0], {_id: ObjectId(@doc_id)} assert.equal args[1]["$set"]["lines"], @lines @@ -67,7 +67,7 @@ describe "MongoManager", -> done() it "should return the error", (done)-> - @MongoManager.upsertIntoDocCollection @project_id, @doc_id, @lines, (err)=> + @MongoManager.upsertIntoDocCollection @project_id, @doc_id, {@lines}, (err)=> err.should.equal @stubbedErr done()