diff --git a/services/docstore/app/coffee/mongojs.coffee b/services/docstore/app/coffee/mongojs.coffee index db3d3c00d8..0153c3cfcd 100644 --- a/services/docstore/app/coffee/mongojs.coffee +++ b/services/docstore/app/coffee/mongojs.coffee @@ -1,6 +1,6 @@ Settings = require "settings-sharelatex" mongojs = require "mongojs" -db = mongojs.connect(Settings.mongo.url, ["docs", "docOps"]) +db = mongojs(Settings.mongo.url, ["docs", "docOps"]) module.exports = db: db ObjectId: mongojs.ObjectId diff --git a/services/docstore/package.json b/services/docstore/package.json index dacc42948e..4d6a7e379a 100644 --- a/services/docstore/package.json +++ b/services/docstore/package.json @@ -11,7 +11,7 @@ "settings-sharelatex": "git+https://github.com/sharelatex/settings-sharelatex.git#v1.0.0", "logger-sharelatex": "git+https://github.com/sharelatex/logger-sharelatex.git#v1.4.0", "metrics-sharelatex": "git+https://github.com/sharelatex/metrics-sharelatex.git#v1.7.1", - "mongojs": "0.18.2", + "mongojs": "2.4.0", "express": "~4.1.1", "underscore": "~1.6.0", "body-parser": "~1.0.2", diff --git a/services/docstore/test/unit/coffee/MongoManagerTests.coffee b/services/docstore/test/unit/coffee/MongoManagerTests.coffee index 1a264bf0d2..8b65402ac3 100644 --- a/services/docstore/test/unit/coffee/MongoManagerTests.coffee +++ b/services/docstore/test/unit/coffee/MongoManagerTests.coffee @@ -26,12 +26,10 @@ describe "MongoManager", -> @MongoManager.findDoc @project_id, @doc_id, @filter, @callback it "should find the doc", -> - @db.docs.find - .calledWith({ - _id: ObjectId(@doc_id) - project_id: ObjectId(@project_id) - }, @filter) - .should.equal true + @db.docs.find.lastCall.args.slice(0,2).should.deep.equal([ + {_id: ObjectId(@doc_id), project_id: ObjectId(@project_id)}, + @filter + ]) it "should call the callback with the doc", -> @callback.calledWith(null, @doc).should.equal true @@ -50,12 +48,9 @@ describe "MongoManager", -> @MongoManager.getProjectsDocs @project_id, include_deleted: false, @filter, @callback it "should find the non-deleted docs via the project_id", -> - @db.docs.find - .calledWith({ - project_id: ObjectId(@project_id) - deleted: { $ne: true } - }, @filter) - .should.equal true + @db.docs.find.lastCall.args.slice(0,1).should.deep.equal([ + {project_id: ObjectId(@project_id), deleted: {$ne: true}} + ]) it "should call the callback with the docs", -> @callback.calledWith(null, [@doc, @doc3, @doc4]).should.equal true @@ -65,11 +60,10 @@ describe "MongoManager", -> @MongoManager.getProjectsDocs @project_id, include_deleted: true, @filter, @callback it "should find all via the project_id", -> - @db.docs.find - .calledWith({ - project_id: ObjectId(@project_id) - }, @filter) - .should.equal true + @db.docs.find.lastCall.args.slice(0,2).should.deep.equal([ + {project_id: ObjectId(@project_id)}, + @filter + ]) it "should call the callback with the docs", -> @callback.calledWith(null, [@doc, @doc3, @doc4]).should.equal true @@ -119,9 +113,10 @@ describe "MongoManager", -> @MongoManager.getDocVersion @doc_id, @callback it "should look for the doc in the database", -> - @db.docOps.find - .calledWith({ doc_id: ObjectId(@doc_id) }, {version: 1}) - .should.equal true + @db.docOps.find.lastCall.args.slice(0,2).should.deep.equal([ + { doc_id: ObjectId(@doc_id) }, + {version: 1} + ]) it "should call the callback with the version", -> @callback.calledWith(null, @version).should.equal true @@ -141,16 +136,11 @@ describe "MongoManager", -> @MongoManager.setDocVersion @doc_id, @version, @callback it "should update the doc version", -> - @db.docOps.update - .calledWith({ - doc_id: ObjectId(@doc_id) - }, { - $set: - version: @version - }, { - upsert: true - }) - .should.equal true + @db.docOps.update.lastCall.args.slice(0,3).should.deep.equal([ + {doc_id: ObjectId(@doc_id)}, + {$set: {version: @version}}, + {upsert: true} + ]) it "should call the callback", -> @callback.called.should.equal true