Преглед на файлове

Merge pull request #15475 from overleaf/csh-issue-11625-mongo-ug-5-docstore

Upgrade mongodb module for docstore from 4.11.0 to 6.2.0

GitOrigin-RevId: 443bdcc80398f7cd21bc78a801af3033d2b8e921
Christopher Hoskin преди 2 години
родител
ревизия
5c70e5c534

+ 79 - 64
package-lock.json

@@ -40753,7 +40753,8 @@
         "celebrate": "^13.0.4",
         "celebrate": "^13.0.4",
         "express": "^4.18.2",
         "express": "^4.18.2",
         "lodash": "^4.17.21",
         "lodash": "^4.17.21",
-        "mongodb": "^4.11.0",
+        "mongodb": "^6.2.0",
+        "mongodb-legacy": "^6.0.1",
         "p-map": "^4.0.0",
         "p-map": "^4.0.0",
         "request": "^2.88.2"
         "request": "^2.88.2"
       },
       },
@@ -40767,29 +40768,6 @@
         "sinon-chai": "^3.7.0"
         "sinon-chai": "^3.7.0"
       }
       }
     },
     },
-    "services/docstore/node_modules/buffer": {
-      "version": "5.7.1",
-      "resolved": "https://registry.npmjs.org/buffer/-/buffer-5.7.1.tgz",
-      "integrity": "sha512-EHcyIPBQ4BSGlvjB16k5KgAJ27CIsHY/2JBmCRReo48y9rQ3MaUzWX3KVlBa4U7MyX02HdVj0K7C3WaB3ju7FQ==",
-      "funding": [
-        {
-          "type": "github",
-          "url": "https://github.com/sponsors/feross"
-        },
-        {
-          "type": "patreon",
-          "url": "https://www.patreon.com/feross"
-        },
-        {
-          "type": "consulting",
-          "url": "https://feross.org/support"
-        }
-      ],
-      "dependencies": {
-        "base64-js": "^1.3.1",
-        "ieee754": "^1.1.13"
-      }
-    },
     "services/docstore/node_modules/celebrate": {
     "services/docstore/node_modules/celebrate": {
       "version": "13.0.4",
       "version": "13.0.4",
       "resolved": "https://registry.npmjs.org/celebrate/-/celebrate-13.0.4.tgz",
       "resolved": "https://registry.npmjs.org/celebrate/-/celebrate-13.0.4.tgz",
@@ -40809,32 +40787,71 @@
         "node": ">=0.3.1"
         "node": ">=0.3.1"
       }
       }
     },
     },
+    "services/docstore/node_modules/gcp-metadata": {
+      "version": "5.3.0",
+      "resolved": "https://registry.npmjs.org/gcp-metadata/-/gcp-metadata-5.3.0.tgz",
+      "integrity": "sha512-FNTkdNEnBdlqF2oatizolQqNANMrcqJt6AAYt99B3y1aLLC8Hc5IOBb+ZnnzllodEEf6xMBp6wRcBbc16fa65w==",
+      "optional": true,
+      "peer": true,
+      "dependencies": {
+        "gaxios": "^5.0.0",
+        "json-bigint": "^1.0.0"
+      },
+      "engines": {
+        "node": ">=12"
+      }
+    },
     "services/docstore/node_modules/mongodb": {
     "services/docstore/node_modules/mongodb": {
-      "version": "4.17.1",
-      "resolved": "https://registry.npmjs.org/mongodb/-/mongodb-4.17.1.tgz",
-      "integrity": "sha512-MBuyYiPUPRTqfH2dV0ya4dcr2E5N52ocBuZ8Sgg/M030nGF78v855B3Z27mZJnp8PxjnUquEnAtjOsphgMZOlQ==",
+      "version": "6.2.0",
+      "resolved": "https://registry.npmjs.org/mongodb/-/mongodb-6.2.0.tgz",
+      "integrity": "sha512-d7OSuGjGWDZ5usZPqfvb36laQ9CPhnWkAGHT61x5P95p/8nMVeH8asloMwW6GcYFeB0Vj4CB/1wOTDG2RA9BFA==",
       "dependencies": {
       "dependencies": {
-        "bson": "^4.7.2",
-        "mongodb-connection-string-url": "^2.6.0",
-        "socks": "^2.7.1"
+        "@mongodb-js/saslprep": "^1.1.0",
+        "bson": "^6.2.0",
+        "mongodb-connection-string-url": "^2.6.0"
       },
       },
       "engines": {
       "engines": {
-        "node": ">=12.9.0"
+        "node": ">=16.20.1"
       },
       },
-      "optionalDependencies": {
-        "@aws-sdk/credential-providers": "^3.186.0",
-        "@mongodb-js/saslprep": "^1.1.0"
+      "peerDependencies": {
+        "@aws-sdk/credential-providers": "^3.188.0",
+        "@mongodb-js/zstd": "^1.1.0",
+        "gcp-metadata": "^5.2.0",
+        "kerberos": "^2.0.1",
+        "mongodb-client-encryption": ">=6.0.0 <7",
+        "snappy": "^7.2.2",
+        "socks": "^2.7.1"
+      },
+      "peerDependenciesMeta": {
+        "@aws-sdk/credential-providers": {
+          "optional": true
+        },
+        "@mongodb-js/zstd": {
+          "optional": true
+        },
+        "gcp-metadata": {
+          "optional": true
+        },
+        "kerberos": {
+          "optional": true
+        },
+        "mongodb-client-encryption": {
+          "optional": true
+        },
+        "snappy": {
+          "optional": true
+        },
+        "socks": {
+          "optional": true
+        }
       }
       }
     },
     },
     "services/docstore/node_modules/mongodb/node_modules/bson": {
     "services/docstore/node_modules/mongodb/node_modules/bson": {
-      "version": "4.7.2",
-      "resolved": "https://registry.npmjs.org/bson/-/bson-4.7.2.tgz",
-      "integrity": "sha512-Ry9wCtIZ5kGqkJoi6aD8KjxFZEx78guTQDnpXWiNthsxzrxAK/i8E6pCHAIZTbaEFWcOCvbecMukfK7XUvyLpQ==",
-      "dependencies": {
-        "buffer": "^5.6.0"
-      },
+      "version": "6.2.0",
+      "resolved": "https://registry.npmjs.org/bson/-/bson-6.2.0.tgz",
+      "integrity": "sha512-ID1cI+7bazPDyL9wYy9GaQ8gEEohWvcUl/Yf0dIdutJxnmInEEyCsb4awy/OiBfall7zBA179Pahi3vCdFze3Q==",
       "engines": {
       "engines": {
-        "node": ">=6.9.0"
+        "node": ">=16.20.1"
       }
       }
     },
     },
     "services/docstore/node_modules/sinon": {
     "services/docstore/node_modules/sinon": {
@@ -50804,7 +50821,8 @@
         "express": "^4.18.2",
         "express": "^4.18.2",
         "lodash": "^4.17.21",
         "lodash": "^4.17.21",
         "mocha": "^10.2.0",
         "mocha": "^10.2.0",
-        "mongodb": "^4.11.0",
+        "mongodb": "^6.2.0",
+        "mongodb-legacy": "^6.0.1",
         "p-map": "^4.0.0",
         "p-map": "^4.0.0",
         "request": "^2.88.2",
         "request": "^2.88.2",
         "sandboxed-module": "~2.0.4",
         "sandboxed-module": "~2.0.4",
@@ -50812,15 +50830,6 @@
         "sinon-chai": "^3.7.0"
         "sinon-chai": "^3.7.0"
       },
       },
       "dependencies": {
       "dependencies": {
-        "buffer": {
-          "version": "5.7.1",
-          "resolved": "https://registry.npmjs.org/buffer/-/buffer-5.7.1.tgz",
-          "integrity": "sha512-EHcyIPBQ4BSGlvjB16k5KgAJ27CIsHY/2JBmCRReo48y9rQ3MaUzWX3KVlBa4U7MyX02HdVj0K7C3WaB3ju7FQ==",
-          "requires": {
-            "base64-js": "^1.3.1",
-            "ieee754": "^1.1.13"
-          }
-        },
         "celebrate": {
         "celebrate": {
           "version": "13.0.4",
           "version": "13.0.4",
           "resolved": "https://registry.npmjs.org/celebrate/-/celebrate-13.0.4.tgz",
           "resolved": "https://registry.npmjs.org/celebrate/-/celebrate-13.0.4.tgz",
@@ -50837,25 +50846,31 @@
           "integrity": "sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A==",
           "integrity": "sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A==",
           "dev": true
           "dev": true
         },
         },
+        "gcp-metadata": {
+          "version": "5.3.0",
+          "resolved": "https://registry.npmjs.org/gcp-metadata/-/gcp-metadata-5.3.0.tgz",
+          "integrity": "sha512-FNTkdNEnBdlqF2oatizolQqNANMrcqJt6AAYt99B3y1aLLC8Hc5IOBb+ZnnzllodEEf6xMBp6wRcBbc16fa65w==",
+          "optional": true,
+          "peer": true,
+          "requires": {
+            "gaxios": "^5.0.0",
+            "json-bigint": "^1.0.0"
+          }
+        },
         "mongodb": {
         "mongodb": {
-          "version": "4.17.1",
-          "resolved": "https://registry.npmjs.org/mongodb/-/mongodb-4.17.1.tgz",
-          "integrity": "sha512-MBuyYiPUPRTqfH2dV0ya4dcr2E5N52ocBuZ8Sgg/M030nGF78v855B3Z27mZJnp8PxjnUquEnAtjOsphgMZOlQ==",
+          "version": "6.2.0",
+          "resolved": "https://registry.npmjs.org/mongodb/-/mongodb-6.2.0.tgz",
+          "integrity": "sha512-d7OSuGjGWDZ5usZPqfvb36laQ9CPhnWkAGHT61x5P95p/8nMVeH8asloMwW6GcYFeB0Vj4CB/1wOTDG2RA9BFA==",
           "requires": {
           "requires": {
-            "@aws-sdk/credential-providers": "^3.186.0",
             "@mongodb-js/saslprep": "^1.1.0",
             "@mongodb-js/saslprep": "^1.1.0",
-            "bson": "^4.7.2",
-            "mongodb-connection-string-url": "^2.6.0",
-            "socks": "^2.7.1"
+            "bson": "^6.2.0",
+            "mongodb-connection-string-url": "^2.6.0"
           },
           },
           "dependencies": {
           "dependencies": {
             "bson": {
             "bson": {
-              "version": "4.7.2",
-              "resolved": "https://registry.npmjs.org/bson/-/bson-4.7.2.tgz",
-              "integrity": "sha512-Ry9wCtIZ5kGqkJoi6aD8KjxFZEx78guTQDnpXWiNthsxzrxAK/i8E6pCHAIZTbaEFWcOCvbecMukfK7XUvyLpQ==",
-              "requires": {
-                "buffer": "^5.6.0"
-              }
+              "version": "6.2.0",
+              "resolved": "https://registry.npmjs.org/bson/-/bson-6.2.0.tgz",
+              "integrity": "sha512-ID1cI+7bazPDyL9wYy9GaQ8gEEohWvcUl/Yf0dIdutJxnmInEEyCsb4awy/OiBfall7zBA179Pahi3vCdFze3Q=="
             }
             }
           }
           }
         },
         },

+ 2 - 2
services/docstore/app/js/HealthChecker.js

@@ -17,8 +17,8 @@ const logger = require('@overleaf/logger')
 
 
 module.exports = {
 module.exports = {
   check(callback) {
   check(callback) {
-    const docId = ObjectId()
-    const projectId = ObjectId(settings.docstore.healthCheck.project_id)
+    const docId = new ObjectId()
+    const projectId = new ObjectId(settings.docstore.healthCheck.project_id)
     const url = `http://localhost:${port}/project/${projectId}/doc/${docId}`
     const url = `http://localhost:${port}/project/${projectId}/doc/${docId}`
     const lines = [
     const lines = [
       'smoke test - delete me',
       'smoke test - delete me',

+ 26 - 23
services/docstore/app/js/MongoManager.js

@@ -11,8 +11,8 @@ const ARCHIVING_LOCK_DURATION_MS = Settings.archivingLockDurationMs
 function findDoc(projectId, docId, filter, callback) {
 function findDoc(projectId, docId, filter, callback) {
   db.docs.findOne(
   db.docs.findOne(
     {
     {
-      _id: ObjectId(docId.toString()),
-      project_id: ObjectId(projectId.toString()),
+      _id: new ObjectId(docId.toString()),
+      project_id: new ObjectId(projectId.toString()),
     },
     },
     {
     {
       projection: filter,
       projection: filter,
@@ -25,7 +25,7 @@ function getProjectsDeletedDocs(projectId, filter, callback) {
   db.docs
   db.docs
     .find(
     .find(
       {
       {
-        project_id: ObjectId(projectId.toString()),
+        project_id: new ObjectId(projectId.toString()),
         deleted: true,
         deleted: true,
       },
       },
       {
       {
@@ -38,7 +38,7 @@ function getProjectsDeletedDocs(projectId, filter, callback) {
 }
 }
 
 
 function getProjectsDocs(projectId, options, filter, callback) {
 function getProjectsDocs(projectId, options, filter, callback) {
-  const query = { project_id: ObjectId(projectId.toString()) }
+  const query = { project_id: new ObjectId(projectId.toString()) }
   if (!options.include_deleted) {
   if (!options.include_deleted) {
     query.deleted = { $ne: true }
     query.deleted = { $ne: true }
   }
   }
@@ -53,7 +53,7 @@ function getProjectsDocs(projectId, options, filter, callback) {
 
 
 function getArchivedProjectDocs(projectId, maxResults, callback) {
 function getArchivedProjectDocs(projectId, maxResults, callback) {
   const query = {
   const query = {
-    project_id: ObjectId(projectId.toString()),
+    project_id: new ObjectId(projectId.toString()),
     inS3: true,
     inS3: true,
   }
   }
   db.docs
   db.docs
@@ -65,7 +65,7 @@ function getNonArchivedProjectDocIds(projectId, callback) {
   db.docs
   db.docs
     .find(
     .find(
       {
       {
-        project_id: ObjectId(projectId),
+        project_id: new ObjectId(projectId),
         inS3: { $ne: true },
         inS3: { $ne: true },
       },
       },
       { projection: { _id: 1 } }
       { projection: { _id: 1 } }
@@ -76,7 +76,7 @@ function getNonArchivedProjectDocIds(projectId, callback) {
 
 
 function getNonDeletedArchivedProjectDocs(projectId, maxResults, callback) {
 function getNonDeletedArchivedProjectDocs(projectId, maxResults, callback) {
   const query = {
   const query = {
-    project_id: ObjectId(projectId.toString()),
+    project_id: new ObjectId(projectId.toString()),
     deleted: { $ne: true },
     deleted: { $ne: true },
     inS3: true,
     inS3: true,
   }
   }
@@ -102,8 +102,8 @@ function upsertIntoDocCollection(
     }
     }
     db.docs.updateOne(
     db.docs.updateOne(
       {
       {
-        _id: ObjectId(docId),
-        project_id: ObjectId(projectId),
+        _id: new ObjectId(docId),
+        project_id: new ObjectId(projectId),
         rev: previousRev,
         rev: previousRev,
       },
       },
       update,
       update,
@@ -118,8 +118,8 @@ function upsertIntoDocCollection(
   } else {
   } else {
     db.docs.insertOne(
     db.docs.insertOne(
       {
       {
-        _id: ObjectId(docId),
-        project_id: ObjectId(projectId),
+        _id: new ObjectId(docId),
+        project_id: new ObjectId(projectId),
         rev: 1,
         rev: 1,
         ...updates,
         ...updates,
       },
       },
@@ -140,8 +140,8 @@ function upsertIntoDocCollection(
 function patchDoc(projectId, docId, meta, callback) {
 function patchDoc(projectId, docId, meta, callback) {
   db.docs.updateOne(
   db.docs.updateOne(
     {
     {
-      _id: ObjectId(docId),
-      project_id: ObjectId(projectId),
+      _id: new ObjectId(docId),
+      project_id: new ObjectId(projectId),
     },
     },
     { $set: meta },
     { $set: meta },
     callback
     callback
@@ -158,13 +158,16 @@ function getDocForArchiving(projectId, docId, callback) {
   const archivingUntil = new Date(Date.now() + ARCHIVING_LOCK_DURATION_MS)
   const archivingUntil = new Date(Date.now() + ARCHIVING_LOCK_DURATION_MS)
   db.docs.findOneAndUpdate(
   db.docs.findOneAndUpdate(
     {
     {
-      _id: ObjectId(docId),
-      project_id: ObjectId(projectId),
+      _id: new ObjectId(docId),
+      project_id: new ObjectId(projectId),
       inS3: { $ne: true },
       inS3: { $ne: true },
       $or: [{ archivingUntil: null }, { archivingUntil: { $lt: new Date() } }],
       $or: [{ archivingUntil: null }, { archivingUntil: { $lt: new Date() } }],
     },
     },
     { $set: { archivingUntil } },
     { $set: { archivingUntil } },
-    { projection: { lines: 1, ranges: 1, rev: 1 } },
+    {
+      projection: { lines: 1, ranges: 1, rev: 1 },
+      includeResultMetadata: true,
+    },
     (err, result) => {
     (err, result) => {
       if (err) {
       if (err) {
         return callback(err)
         return callback(err)
@@ -179,7 +182,7 @@ function getDocForArchiving(projectId, docId, callback) {
  */
  */
 function markDocAsArchived(projectId, docId, rev, callback) {
 function markDocAsArchived(projectId, docId, rev, callback) {
   db.docs.updateOne(
   db.docs.updateOne(
-    { _id: ObjectId(docId), rev },
+    { _id: new ObjectId(docId), rev },
     {
     {
       $set: { inS3: true },
       $set: { inS3: true },
       $unset: { lines: 1, ranges: 1, archivingUntil: 1 },
       $unset: { lines: 1, ranges: 1, archivingUntil: 1 },
@@ -195,8 +198,8 @@ function markDocAsArchived(projectId, docId, rev, callback) {
  */
  */
 function restoreArchivedDoc(projectId, docId, archivedDoc, callback) {
 function restoreArchivedDoc(projectId, docId, archivedDoc, callback) {
   const query = {
   const query = {
-    _id: ObjectId(docId),
-    project_id: ObjectId(projectId),
+    _id: new ObjectId(docId),
+    project_id: new ObjectId(projectId),
     rev: archivedDoc.rev,
     rev: archivedDoc.rev,
   }
   }
   const update = {
   const update = {
@@ -231,7 +234,7 @@ function restoreArchivedDoc(projectId, docId, archivedDoc, callback) {
 function getDocVersion(docId, callback) {
 function getDocVersion(docId, callback) {
   db.docOps.findOne(
   db.docOps.findOne(
     {
     {
-      doc_id: ObjectId(docId),
+      doc_id: new ObjectId(docId),
     },
     },
     {
     {
       projection: {
       projection: {
@@ -250,7 +253,7 @@ function getDocVersion(docId, callback) {
 function getDocRev(docId, callback) {
 function getDocRev(docId, callback) {
   db.docs.findOne(
   db.docs.findOne(
     {
     {
-      _id: ObjectId(docId.toString()),
+      _id: new ObjectId(docId.toString()),
     },
     },
     {
     {
       projection: { rev: 1 },
       projection: { rev: 1 },
@@ -297,7 +300,7 @@ function checkRevUnchanged(doc, callback) {
 
 
 function destroyProject(projectId, callback) {
 function destroyProject(projectId, callback) {
   db.docs
   db.docs
-    .find({ project_id: ObjectId(projectId) }, { projection: { _id: 1 } })
+    .find({ project_id: new ObjectId(projectId) }, { projection: { _id: 1 } })
     .toArray((err, records) => {
     .toArray((err, records) => {
       const docIds = records.map(r => r._id)
       const docIds = records.map(r => r._id)
       if (err) {
       if (err) {
@@ -307,7 +310,7 @@ function destroyProject(projectId, callback) {
         if (err) {
         if (err) {
           return callback(err)
           return callback(err)
         }
         }
-        db.docs.deleteMany({ project_id: ObjectId(projectId) }, callback)
+        db.docs.deleteMany({ project_id: new ObjectId(projectId) }, callback)
       })
       })
     })
     })
 }
 }

+ 1 - 1
services/docstore/app/js/RangeManager.js

@@ -60,7 +60,7 @@ module.exports = RangeManager = {
 
 
   _safeObjectId(data) {
   _safeObjectId(data) {
     try {
     try {
-      return ObjectId(data)
+      return new ObjectId(data)
     } catch (error) {
     } catch (error) {
       return data
       return data
     }
     }

+ 1 - 1
services/docstore/app/js/mongodb.js

@@ -1,6 +1,6 @@
 const Metrics = require('@overleaf/metrics')
 const Metrics = require('@overleaf/metrics')
 const Settings = require('@overleaf/settings')
 const Settings = require('@overleaf/settings')
-const { MongoClient, ObjectId } = require('mongodb')
+const { MongoClient, ObjectId } = require('mongodb-legacy')
 
 
 const mongoClient = new MongoClient(Settings.mongo.url)
 const mongoClient = new MongoClient(Settings.mongo.url)
 const mongoDb = mongoClient.db()
 const mongoDb = mongoClient.db()

+ 2 - 1
services/docstore/package.json

@@ -30,7 +30,8 @@
     "celebrate": "^13.0.4",
     "celebrate": "^13.0.4",
     "express": "^4.18.2",
     "express": "^4.18.2",
     "lodash": "^4.17.21",
     "lodash": "^4.17.21",
-    "mongodb": "^4.11.0",
+    "mongodb": "^6.2.0",
+    "mongodb-legacy": "^6.0.1",
     "p-map": "^4.0.0",
     "p-map": "^4.0.0",
     "request": "^2.88.2"
     "request": "^2.88.2"
   },
   },

+ 25 - 25
services/docstore/test/acceptance/js/ArchiveDocsTests.js

@@ -50,16 +50,16 @@ describe('Archiving', function () {
 
 
   describe('multiple docs in a project', function () {
   describe('multiple docs in a project', function () {
     before(function (done) {
     before(function (done) {
-      this.project_id = ObjectId()
+      this.project_id = new ObjectId()
       this.docs = [
       this.docs = [
         {
         {
-          _id: ObjectId(),
+          _id: new ObjectId(),
           lines: ['one', 'two', 'three'],
           lines: ['one', 'two', 'three'],
           ranges: {},
           ranges: {},
           version: 2,
           version: 2,
         },
         },
         {
         {
-          _id: ObjectId(),
+          _id: new ObjectId(),
           lines: ['aaa', 'bbb', 'ccc'],
           lines: ['aaa', 'bbb', 'ccc'],
           ranges: {},
           ranges: {},
           version: 4,
           version: 4,
@@ -177,9 +177,9 @@ describe('Archiving', function () {
 
 
   describe('a deleted doc', function () {
   describe('a deleted doc', function () {
     beforeEach(function (done) {
     beforeEach(function (done) {
-      this.project_id = ObjectId()
+      this.project_id = new ObjectId()
       this.doc = {
       this.doc = {
-        _id: ObjectId(),
+        _id: new ObjectId(),
         lines: ['one', 'two', 'three'],
         lines: ['one', 'two', 'three'],
         ranges: {},
         ranges: {},
         version: 2,
         version: 2,
@@ -332,10 +332,10 @@ describe('Archiving', function () {
 
 
   describe('archiving a single doc', function () {
   describe('archiving a single doc', function () {
     before(function (done) {
     before(function (done) {
-      this.project_id = ObjectId()
+      this.project_id = new ObjectId()
       this.timeout(1000 * 30)
       this.timeout(1000 * 30)
       this.doc = {
       this.doc = {
-        _id: ObjectId(),
+        _id: new ObjectId(),
         lines: ['foo', 'bar'],
         lines: ['foo', 'bar'],
         ranges: {},
         ranges: {},
         version: 2,
         version: 2,
@@ -396,14 +396,14 @@ describe('Archiving', function () {
 
 
   describe('a doc with large lines', function () {
   describe('a doc with large lines', function () {
     before(function (done) {
     before(function (done) {
-      this.project_id = ObjectId()
+      this.project_id = new ObjectId()
       this.timeout(1000 * 30)
       this.timeout(1000 * 30)
       const quarterMegInBytes = 250000
       const quarterMegInBytes = 250000
       const bigLine = require('crypto')
       const bigLine = require('crypto')
         .randomBytes(quarterMegInBytes)
         .randomBytes(quarterMegInBytes)
         .toString('hex')
         .toString('hex')
       this.doc = {
       this.doc = {
-        _id: ObjectId(),
+        _id: new ObjectId(),
         lines: [bigLine, bigLine, bigLine, bigLine],
         lines: [bigLine, bigLine, bigLine, bigLine],
         ranges: {},
         ranges: {},
         version: 2,
         version: 2,
@@ -491,9 +491,9 @@ describe('Archiving', function () {
 
 
   describe('a doc with naughty strings', function () {
   describe('a doc with naughty strings', function () {
     before(function (done) {
     before(function (done) {
-      this.project_id = ObjectId()
+      this.project_id = new ObjectId()
       this.doc = {
       this.doc = {
-        _id: ObjectId(),
+        _id: new ObjectId(),
         lines: [
         lines: [
           '',
           '',
           'undefined',
           'undefined',
@@ -965,35 +965,35 @@ describe('Archiving', function () {
 
 
   describe('a doc with ranges', function () {
   describe('a doc with ranges', function () {
     before(function (done) {
     before(function (done) {
-      this.project_id = ObjectId()
+      this.project_id = new ObjectId()
       this.doc = {
       this.doc = {
-        _id: ObjectId(),
+        _id: new ObjectId(),
         lines: ['one', 'two', 'three'],
         lines: ['one', 'two', 'three'],
         ranges: {
         ranges: {
           changes: [
           changes: [
             {
             {
-              id: ObjectId(),
+              id: new ObjectId(),
               op: { i: 'foo', p: 24 },
               op: { i: 'foo', p: 24 },
               metadata: {
               metadata: {
-                user_id: ObjectId(),
+                user_id: new ObjectId(),
                 ts: new Date('2017-01-27T16:10:44.194Z'),
                 ts: new Date('2017-01-27T16:10:44.194Z'),
               },
               },
             },
             },
             {
             {
-              id: ObjectId(),
+              id: new ObjectId(),
               op: { d: 'bar', p: 50 },
               op: { d: 'bar', p: 50 },
               metadata: {
               metadata: {
-                user_id: ObjectId(),
+                user_id: new ObjectId(),
                 ts: new Date('2017-01-27T18:10:44.194Z'),
                 ts: new Date('2017-01-27T18:10:44.194Z'),
               },
               },
             },
             },
           ],
           ],
           comments: [
           comments: [
             {
             {
-              id: ObjectId(),
-              op: { c: 'comment', p: 284, t: ObjectId() },
+              id: new ObjectId(),
+              op: { c: 'comment', p: 284, t: new ObjectId() },
               metadata: {
               metadata: {
-                user_id: ObjectId(),
+                user_id: new ObjectId(),
                 ts: new Date('2017-01-26T14:22:04.869Z'),
                 ts: new Date('2017-01-26T14:22:04.869Z'),
               },
               },
             },
             },
@@ -1085,9 +1085,9 @@ describe('Archiving', function () {
 
 
   describe('a doc that is archived twice', function () {
   describe('a doc that is archived twice', function () {
     before(function (done) {
     before(function (done) {
-      this.project_id = ObjectId()
+      this.project_id = new ObjectId()
       this.doc = {
       this.doc = {
-        _id: ObjectId(),
+        _id: new ObjectId(),
         lines: ['abc', 'def', 'ghi'],
         lines: ['abc', 'def', 'ghi'],
         ranges: {},
         ranges: {},
         version: 2,
         version: 2,
@@ -1181,9 +1181,9 @@ describe('Archiving', function () {
 
 
   return describe('a doc with the old schema (just an array of lines)', function () {
   return describe('a doc with the old schema (just an array of lines)', function () {
     before(function (done) {
     before(function (done) {
-      this.project_id = ObjectId()
+      this.project_id = new ObjectId()
       this.doc = {
       this.doc = {
-        _id: ObjectId(),
+        _id: new ObjectId(),
         lines: ['abc', 'def', 'ghi'],
         lines: ['abc', 'def', 'ghi'],
         ranges: {},
         ranges: {},
         version: 2,
         version: 2,
@@ -1193,7 +1193,7 @@ describe('Archiving', function () {
         this.doc.lines,
         this.doc.lines,
         error => {
         error => {
           expect(error).not.to.exist
           expect(error).not.to.exist
-          db.docs.insert(
+          db.docs.insertOne(
             {
             {
               project_id: this.project_id,
               project_id: this.project_id,
               _id: this.doc._id,
               _id: this.doc._id,

+ 19 - 16
services/docstore/test/acceptance/js/DeletingDocsTests.js

@@ -25,8 +25,8 @@ function deleteTestSuite(deleteDoc) {
   })
   })
 
 
   beforeEach(function (done) {
   beforeEach(function (done) {
-    this.project_id = ObjectId()
-    this.doc_id = ObjectId()
+    this.project_id = new ObjectId()
+    this.doc_id = new ObjectId()
     this.lines = ['original', 'lines']
     this.lines = ['original', 'lines']
     this.version = 42
     this.version = 42
     this.ranges = []
     this.ranges = []
@@ -70,7 +70,7 @@ function deleteTestSuite(deleteDoc) {
     })
     })
 
 
     afterEach(function (done) {
     afterEach(function (done) {
-      db.docs.remove({ _id: this.doc_id }, done)
+      db.docs.deleteOne({ _id: this.doc_id }, done)
     })
     })
 
 
     it('should mark the doc as deleted on /deleted', function (done) {
     it('should mark the doc as deleted on /deleted', function (done) {
@@ -129,7 +129,7 @@ function deleteTestSuite(deleteDoc) {
     })
     })
 
 
     afterEach(function cleanupDoc(done) {
     afterEach(function cleanupDoc(done) {
-      db.docs.remove({ _id: this.doc_id }, done)
+      db.docs.deleteOne({ _id: this.doc_id }, done)
     })
     })
 
 
     it('should set the deleted flag in the doc', function (done) {
     it('should set the deleted flag in the doc', function (done) {
@@ -167,7 +167,7 @@ function deleteTestSuite(deleteDoc) {
   })
   })
 
 
   describe('when the doc exists in another project', function () {
   describe('when the doc exists in another project', function () {
-    const otherProjectId = ObjectId()
+    const otherProjectId = new ObjectId()
 
 
     it('should show as not existing on /deleted', function (done) {
     it('should show as not existing on /deleted', function (done) {
       DocstoreClient.isDocDeleted(otherProjectId, this.doc_id, (error, res) => {
       DocstoreClient.isDocDeleted(otherProjectId, this.doc_id, (error, res) => {
@@ -188,7 +188,7 @@ function deleteTestSuite(deleteDoc) {
 
 
   describe('when the doc does not exist', function () {
   describe('when the doc does not exist', function () {
     it('should show as not existing on /deleted', function (done) {
     it('should show as not existing on /deleted', function (done) {
-      const missingDocId = ObjectId()
+      const missingDocId = new ObjectId()
       DocstoreClient.isDocDeleted(
       DocstoreClient.isDocDeleted(
         this.project_id,
         this.project_id,
         missingDocId,
         missingDocId,
@@ -201,7 +201,7 @@ function deleteTestSuite(deleteDoc) {
     })
     })
 
 
     it('should return a 404', function (done) {
     it('should return a 404', function (done) {
-      const missingDocId = ObjectId()
+      const missingDocId = new ObjectId()
       deleteDoc(this.project_id, missingDocId, (error, res, doc) => {
       deleteDoc(this.project_id, missingDocId, (error, res, doc) => {
         if (error) return done(error)
         if (error) return done(error)
         res.statusCode.should.equal(404)
         res.statusCode.should.equal(404)
@@ -338,7 +338,7 @@ describe('Delete via PATCH', function () {
 
 
     describe('after deleting multiple docs', function () {
     describe('after deleting multiple docs', function () {
       beforeEach('create doc2', function (done) {
       beforeEach('create doc2', function (done) {
-        this.doc_id2 = ObjectId()
+        this.doc_id2 = new ObjectId()
         DocstoreClient.createDoc(
         DocstoreClient.createDoc(
           this.project_id,
           this.project_id,
           this.doc_id2,
           this.doc_id2,
@@ -359,7 +359,7 @@ describe('Delete via PATCH', function () {
         )
         )
       })
       })
       beforeEach('create doc3', function (done) {
       beforeEach('create doc3', function (done) {
-        this.doc_id3 = ObjectId()
+        this.doc_id3 = new ObjectId()
         DocstoreClient.createDoc(
         DocstoreClient.createDoc(
           this.project_id,
           this.project_id,
           this.doc_id3,
           this.doc_id3,
@@ -447,8 +447,8 @@ describe('Delete via PATCH', function () {
 
 
 describe("Destroying a project's documents", function () {
 describe("Destroying a project's documents", function () {
   beforeEach(function (done) {
   beforeEach(function (done) {
-    this.project_id = ObjectId()
-    this.doc_id = ObjectId()
+    this.project_id = new ObjectId()
+    this.doc_id = new ObjectId()
     this.lines = ['original', 'lines']
     this.lines = ['original', 'lines']
     this.version = 42
     this.version = 42
     this.ranges = []
     this.ranges = []
@@ -471,12 +471,15 @@ describe("Destroying a project's documents", function () {
 
 
   describe('when the doc exists', function () {
   describe('when the doc exists', function () {
     beforeEach(function (done) {
     beforeEach(function (done) {
-      db.docOps.insert({ doc_id: ObjectId(this.doc_id), version: 1 }, err => {
-        if (err) {
-          return done(err)
+      db.docOps.insertOne(
+        { doc_id: new ObjectId(this.doc_id), version: 1 },
+        err => {
+          if (err) {
+            return done(err)
+          }
+          DocstoreClient.destroyAllDoc(this.project_id, done)
         }
         }
-        DocstoreClient.destroyAllDoc(this.project_id, done)
-      })
+      )
     })
     })
 
 
     it('should remove the doc from the docs collection', function (done) {
     it('should remove the doc from the docs collection', function (done) {

+ 5 - 5
services/docstore/test/acceptance/js/GettingAllDocsTests.js

@@ -19,29 +19,29 @@ const DocstoreClient = require('./helpers/DocstoreClient')
 
 
 describe('Getting all docs', function () {
 describe('Getting all docs', function () {
   beforeEach(function (done) {
   beforeEach(function (done) {
-    this.project_id = ObjectId()
+    this.project_id = new ObjectId()
     this.docs = [
     this.docs = [
       {
       {
-        _id: ObjectId(),
+        _id: new ObjectId(),
         lines: ['one', 'two', 'three'],
         lines: ['one', 'two', 'three'],
         ranges: { mock: 'one' },
         ranges: { mock: 'one' },
         rev: 2,
         rev: 2,
       },
       },
       {
       {
-        _id: ObjectId(),
+        _id: new ObjectId(),
         lines: ['aaa', 'bbb', 'ccc'],
         lines: ['aaa', 'bbb', 'ccc'],
         ranges: { mock: 'two' },
         ranges: { mock: 'two' },
         rev: 4,
         rev: 4,
       },
       },
       {
       {
-        _id: ObjectId(),
+        _id: new ObjectId(),
         lines: ['111', '222', '333'],
         lines: ['111', '222', '333'],
         ranges: { mock: 'three' },
         ranges: { mock: 'three' },
         rev: 6,
         rev: 6,
       },
       },
     ]
     ]
     this.deleted_doc = {
     this.deleted_doc = {
-      _id: ObjectId(),
+      _id: new ObjectId(),
       lines: ['deleted'],
       lines: ['deleted'],
       ranges: { mock: 'four' },
       ranges: { mock: 'four' },
       rev: 8,
       rev: 8,

+ 4 - 4
services/docstore/test/acceptance/js/GettingDocsFromArchiveTest.js

@@ -26,10 +26,10 @@ describe('Getting A Doc from Archive', function () {
 
 
   describe('for an archived doc', function () {
   describe('for an archived doc', function () {
     before(function (done) {
     before(function (done) {
-      this.project_id = ObjectId()
+      this.project_id = new ObjectId()
       this.timeout(1000 * 30)
       this.timeout(1000 * 30)
       this.doc = {
       this.doc = {
-        _id: ObjectId(),
+        _id: new ObjectId(),
         lines: ['foo', 'bar'],
         lines: ['foo', 'bar'],
         ranges: {},
         ranges: {},
         version: 2,
         version: 2,
@@ -100,10 +100,10 @@ describe('Getting A Doc from Archive', function () {
 
 
     describe('for an non-archived doc', function () {
     describe('for an non-archived doc', function () {
       before(function (done) {
       before(function (done) {
-        this.project_id = ObjectId()
+        this.project_id = new ObjectId()
         this.timeout(1000 * 30)
         this.timeout(1000 * 30)
         this.doc = {
         this.doc = {
-          _id: ObjectId(),
+          _id: new ObjectId(),
           lines: ['foo', 'bar'],
           lines: ['foo', 'bar'],
           ranges: {},
           ranges: {},
           version: 2,
           version: 2,

+ 6 - 6
services/docstore/test/acceptance/js/GettingDocsTests.js

@@ -17,17 +17,17 @@ const DocstoreClient = require('./helpers/DocstoreClient')
 
 
 describe('Getting a doc', function () {
 describe('Getting a doc', function () {
   beforeEach(function (done) {
   beforeEach(function (done) {
-    this.project_id = ObjectId()
-    this.doc_id = ObjectId()
+    this.project_id = new ObjectId()
+    this.doc_id = new ObjectId()
     this.lines = ['original', 'lines']
     this.lines = ['original', 'lines']
     this.version = 42
     this.version = 42
     this.ranges = {
     this.ranges = {
       changes: [
       changes: [
         {
         {
-          id: ObjectId().toString(),
+          id: new ObjectId().toString(),
           op: { i: 'foo', p: 3 },
           op: { i: 'foo', p: 3 },
           meta: {
           meta: {
-            user_id: ObjectId().toString(),
+            user_id: new ObjectId().toString(),
             ts: new Date().toString(),
             ts: new Date().toString(),
           },
           },
         },
         },
@@ -69,7 +69,7 @@ describe('Getting a doc', function () {
 
 
   describe('when the doc does not exist', function () {
   describe('when the doc does not exist', function () {
     return it('should return a 404', function (done) {
     return it('should return a 404', function (done) {
-      const missingDocId = ObjectId()
+      const missingDocId = new ObjectId()
       return DocstoreClient.getDoc(
       return DocstoreClient.getDoc(
         this.project_id,
         this.project_id,
         missingDocId,
         missingDocId,
@@ -85,7 +85,7 @@ describe('Getting a doc', function () {
 
 
   return describe('when the doc is a deleted doc', function () {
   return describe('when the doc is a deleted doc', function () {
     beforeEach(function (done) {
     beforeEach(function (done) {
-      this.deleted_doc_id = ObjectId()
+      this.deleted_doc_id = new ObjectId()
       return DocstoreClient.createDoc(
       return DocstoreClient.createDoc(
         this.project_id,
         this.project_id,
         this.deleted_doc_id,
         this.deleted_doc_id,

+ 7 - 7
services/docstore/test/acceptance/js/UpdatingDocsTests.js

@@ -17,17 +17,17 @@ const DocstoreClient = require('./helpers/DocstoreClient')
 
 
 describe('Applying updates to a doc', function () {
 describe('Applying updates to a doc', function () {
   beforeEach(function (done) {
   beforeEach(function (done) {
-    this.project_id = ObjectId()
-    this.doc_id = ObjectId()
+    this.project_id = new ObjectId()
+    this.doc_id = new ObjectId()
     this.originalLines = ['original', 'lines']
     this.originalLines = ['original', 'lines']
     this.newLines = ['new', 'lines']
     this.newLines = ['new', 'lines']
     this.originalRanges = {
     this.originalRanges = {
       changes: [
       changes: [
         {
         {
-          id: ObjectId().toString(),
+          id: new ObjectId().toString(),
           op: { i: 'foo', p: 3 },
           op: { i: 'foo', p: 3 },
           meta: {
           meta: {
-            user_id: ObjectId().toString(),
+            user_id: new ObjectId().toString(),
             ts: new Date().toString(),
             ts: new Date().toString(),
           },
           },
         },
         },
@@ -36,10 +36,10 @@ describe('Applying updates to a doc', function () {
     this.newRanges = {
     this.newRanges = {
       changes: [
       changes: [
         {
         {
-          id: ObjectId().toString(),
+          id: new ObjectId().toString(),
           op: { i: 'bar', p: 6 },
           op: { i: 'bar', p: 6 },
           meta: {
           meta: {
-            user_id: ObjectId().toString(),
+            user_id: new ObjectId().toString(),
             ts: new Date().toString(),
             ts: new Date().toString(),
           },
           },
         },
         },
@@ -258,7 +258,7 @@ describe('Applying updates to a doc', function () {
 
 
   describe('when the doc does not exist', function () {
   describe('when the doc does not exist', function () {
     beforeEach(function (done) {
     beforeEach(function (done) {
-      this.missing_doc_id = ObjectId()
+      this.missing_doc_id = new ObjectId()
       return DocstoreClient.updateDoc(
       return DocstoreClient.updateDoc(
         this.project_id,
         this.project_id,
         this.missing_doc_id,
         this.missing_doc_id,

+ 9 - 9
services/docstore/test/unit/js/DocArchiveManagerTests.js

@@ -46,47 +46,47 @@ describe('DocArchiveManager', function () {
       ReadableString: sinon.stub().returns({ stream: 'readStream' }),
       ReadableString: sinon.stub().returns({ stream: 'readStream' }),
     }
     }
 
 
-    projectId = ObjectId()
+    projectId = new ObjectId()
     archivedDocs = [
     archivedDocs = [
       {
       {
-        _id: ObjectId(),
+        _id: new ObjectId(),
         inS3: true,
         inS3: true,
         rev: 2,
         rev: 2,
       },
       },
       {
       {
-        _id: ObjectId(),
+        _id: new ObjectId(),
         inS3: true,
         inS3: true,
         rev: 4,
         rev: 4,
       },
       },
       {
       {
-        _id: ObjectId(),
+        _id: new ObjectId(),
         inS3: true,
         inS3: true,
         rev: 6,
         rev: 6,
       },
       },
     ]
     ]
     mongoDocs = [
     mongoDocs = [
       {
       {
-        _id: ObjectId(),
+        _id: new ObjectId(),
         lines: ['one', 'two', 'three'],
         lines: ['one', 'two', 'three'],
         rev: 2,
         rev: 2,
       },
       },
       {
       {
-        _id: ObjectId(),
+        _id: new ObjectId(),
         lines: ['aaa', 'bbb', 'ccc'],
         lines: ['aaa', 'bbb', 'ccc'],
         rev: 4,
         rev: 4,
       },
       },
       {
       {
-        _id: ObjectId(),
+        _id: new ObjectId(),
         inS3: true,
         inS3: true,
         rev: 6,
         rev: 6,
       },
       },
       {
       {
-        _id: ObjectId(),
+        _id: new ObjectId(),
         inS3: true,
         inS3: true,
         rev: 6,
         rev: 6,
       },
       },
       {
       {
-        _id: ObjectId(),
+        _id: new ObjectId(),
         lines: ['111', '222', '333'],
         lines: ['111', '222', '333'],
         rev: 6,
         rev: 6,
       },
       },

+ 8 - 8
services/docstore/test/unit/js/DocManagerTests.js

@@ -7,9 +7,9 @@ const Errors = require('../../../app/js/Errors')
 
 
 describe('DocManager', function () {
 describe('DocManager', function () {
   beforeEach(function () {
   beforeEach(function () {
-    this.doc_id = ObjectId().toString()
-    this.project_id = ObjectId().toString()
-    this.another_project_id = ObjectId().toString()
+    this.doc_id = new ObjectId().toString()
+    this.project_id = new ObjectId().toString()
+    this.another_project_id = new ObjectId().toString()
     this.stubbedError = new Error('blew up')
     this.stubbedError = new Error('blew up')
     this.version = 42
     this.version = 42
 
 
@@ -343,7 +343,7 @@ describe('DocManager', function () {
         this.lines = ['mock', 'doc', 'lines']
         this.lines = ['mock', 'doc', 'lines']
         this.rev = 77
         this.rev = 77
         this.MongoManager.promises.findDoc.resolves({
         this.MongoManager.promises.findDoc.resolves({
-          _id: ObjectId(this.doc_id),
+          _id: new ObjectId(this.doc_id),
         })
         })
         this.meta = {}
         this.meta = {}
       })
       })
@@ -478,10 +478,10 @@ describe('DocManager', function () {
       this.originalRanges = {
       this.originalRanges = {
         changes: [
         changes: [
           {
           {
-            id: ObjectId().toString(),
+            id: new ObjectId().toString(),
             op: { i: 'foo', p: 3 },
             op: { i: 'foo', p: 3 },
             meta: {
             meta: {
-              user_id: ObjectId().toString(),
+              user_id: new ObjectId().toString(),
               ts: new Date().toString(),
               ts: new Date().toString(),
             },
             },
           },
           },
@@ -490,10 +490,10 @@ describe('DocManager', function () {
       this.newRanges = {
       this.newRanges = {
         changes: [
         changes: [
           {
           {
-            id: ObjectId().toString(),
+            id: new ObjectId().toString(),
             op: { i: 'bar', p: 6 },
             op: { i: 'bar', p: 6 },
             meta: {
             meta: {
-              user_id: ObjectId().toString(),
+              user_id: new ObjectId().toString(),
               ts: new Date().toString(),
               ts: new Date().toString(),
             },
             },
           },
           },

+ 8 - 8
services/docstore/test/unit/js/HttpControllerTests.js

@@ -158,12 +158,12 @@ describe('HttpController', function () {
         this.req.params = { project_id: this.projectId }
         this.req.params = { project_id: this.projectId }
         this.docs = [
         this.docs = [
           {
           {
-            _id: ObjectId(),
+            _id: new ObjectId(),
             lines: ['mock', 'lines', 'one'],
             lines: ['mock', 'lines', 'one'],
             rev: 2,
             rev: 2,
           },
           },
           {
           {
-            _id: ObjectId(),
+            _id: new ObjectId(),
             lines: ['mock', 'lines', 'two'],
             lines: ['mock', 'lines', 'two'],
             rev: 4,
             rev: 4,
           },
           },
@@ -203,12 +203,12 @@ describe('HttpController', function () {
         this.req.params = { project_id: this.projectId }
         this.req.params = { project_id: this.projectId }
         this.docs = [
         this.docs = [
           {
           {
-            _id: ObjectId(),
+            _id: new ObjectId(),
             lines: null,
             lines: null,
             rev: 2,
             rev: 2,
           },
           },
           {
           {
-            _id: ObjectId(),
+            _id: new ObjectId(),
             lines: ['mock', 'lines', 'two'],
             lines: ['mock', 'lines', 'two'],
             rev: 4,
             rev: 4,
           },
           },
@@ -242,13 +242,13 @@ describe('HttpController', function () {
         this.req.params = { project_id: this.projectId }
         this.req.params = { project_id: this.projectId }
         this.docs = [
         this.docs = [
           {
           {
-            _id: ObjectId(),
+            _id: new ObjectId(),
             lines: ['mock', 'lines', 'one'],
             lines: ['mock', 'lines', 'one'],
             rev: 2,
             rev: 2,
           },
           },
           null,
           null,
           {
           {
-            _id: ObjectId(),
+            _id: new ObjectId(),
             lines: ['mock', 'lines', 'two'],
             lines: ['mock', 'lines', 'two'],
             rev: 4,
             rev: 4,
           },
           },
@@ -296,11 +296,11 @@ describe('HttpController', function () {
         this.req.params = { project_id: this.projectId }
         this.req.params = { project_id: this.projectId }
         this.docs = [
         this.docs = [
           {
           {
-            _id: ObjectId(),
+            _id: new ObjectId(),
             ranges: { mock_ranges: 'one' },
             ranges: { mock_ranges: 'one' },
           },
           },
           {
           {
-            _id: ObjectId(),
+            _id: new ObjectId(),
             ranges: { mock_ranges: 'two' },
             ranges: { mock_ranges: 'two' },
           },
           },
         ]
         ]

+ 22 - 22
services/docstore/test/unit/js/MongoManagerTests.js

@@ -31,8 +31,8 @@ describe('MongoManager', function () {
         './Errors': Errors,
         './Errors': Errors,
       },
       },
     })
     })
-    this.projectId = ObjectId().toString()
-    this.docId = ObjectId().toString()
+    this.projectId = new ObjectId().toString()
+    this.docId = new ObjectId().toString()
     this.rev = 42
     this.rev = 42
     this.callback = sinon.stub()
     this.callback = sinon.stub()
     this.stubbedErr = new Error('hello world')
     this.stubbedErr = new Error('hello world')
@@ -56,8 +56,8 @@ describe('MongoManager', function () {
       this.db.docs.findOne
       this.db.docs.findOne
         .calledWith(
         .calledWith(
           {
           {
-            _id: ObjectId(this.docId),
-            project_id: ObjectId(this.projectId),
+            _id: new ObjectId(this.docId),
+            project_id: new ObjectId(this.projectId),
           },
           },
           {
           {
             projection: this.filter,
             projection: this.filter,
@@ -86,8 +86,8 @@ describe('MongoManager', function () {
     it('should pass the parameter along', function () {
     it('should pass the parameter along', function () {
       this.db.docs.updateOne.should.have.been.calledWith(
       this.db.docs.updateOne.should.have.been.calledWith(
         {
         {
-          _id: ObjectId(this.docId),
-          project_id: ObjectId(this.projectId),
+          _id: new ObjectId(this.docId),
+          project_id: new ObjectId(this.projectId),
         },
         },
         {
         {
           $set: this.meta,
           $set: this.meta,
@@ -125,7 +125,7 @@ describe('MongoManager', function () {
         this.db.docs.find
         this.db.docs.find
           .calledWith(
           .calledWith(
             {
             {
-              project_id: ObjectId(this.projectId),
+              project_id: new ObjectId(this.projectId),
               deleted: { $ne: true },
               deleted: { $ne: true },
             },
             },
             {
             {
@@ -156,7 +156,7 @@ describe('MongoManager', function () {
         this.db.docs.find
         this.db.docs.find
           .calledWith(
           .calledWith(
             {
             {
-              project_id: ObjectId(this.projectId),
+              project_id: new ObjectId(this.projectId),
             },
             },
             {
             {
               projection: this.filter,
               projection: this.filter,
@@ -193,7 +193,7 @@ describe('MongoManager', function () {
     it('should find the deleted docs via the project_id', function () {
     it('should find the deleted docs via the project_id', function () {
       this.db.docs.find
       this.db.docs.find
         .calledWith({
         .calledWith({
-          project_id: ObjectId(this.projectId),
+          project_id: new ObjectId(this.projectId),
           deleted: true,
           deleted: true,
         })
         })
         .should.equal(true)
         .should.equal(true)
@@ -231,8 +231,8 @@ describe('MongoManager', function () {
           assert.equal(err, null)
           assert.equal(err, null)
           const args = this.db.docs.updateOne.args[0]
           const args = this.db.docs.updateOne.args[0]
           assert.deepEqual(args[0], {
           assert.deepEqual(args[0], {
-            _id: ObjectId(this.docId),
-            project_id: ObjectId(this.projectId),
+            _id: new ObjectId(this.docId),
+            project_id: new ObjectId(this.projectId),
             rev: this.oldRev,
             rev: this.oldRev,
           })
           })
           assert.equal(args[1].$set.lines, this.lines)
           assert.equal(args[1].$set.lines, this.lines)
@@ -264,8 +264,8 @@ describe('MongoManager', function () {
         { lines: this.lines, ranges: this.ranges },
         { lines: this.lines, ranges: this.ranges },
         err => {
         err => {
           expect(this.db.docs.insertOne).to.have.been.calledWith({
           expect(this.db.docs.insertOne).to.have.been.calledWith({
-            _id: ObjectId(this.docId),
-            project_id: ObjectId(this.projectId),
+            _id: new ObjectId(this.docId),
+            project_id: new ObjectId(this.projectId),
             rev: 1,
             rev: 1,
             lines: this.lines,
             lines: this.lines,
             ranges: this.ranges,
             ranges: this.ranges,
@@ -307,8 +307,8 @@ describe('MongoManager', function () {
 
 
   describe('destroyProject', function () {
   describe('destroyProject', function () {
     beforeEach(function (done) {
     beforeEach(function (done) {
-      this.projectId = ObjectId()
-      this.docIds = [ObjectId(), ObjectId()]
+      this.projectId = new ObjectId()
+      this.docIds = [new ObjectId(), new ObjectId()]
       this.db.docs.deleteMany = sinon.stub().yields()
       this.db.docs.deleteMany = sinon.stub().yields()
       this.db.docOps.deleteMany = sinon.stub().yields()
       this.db.docOps.deleteMany = sinon.stub().yields()
       this.db.docs.find = sinon
       this.db.docs.find = sinon
@@ -349,7 +349,7 @@ describe('MongoManager', function () {
       it('should look for the doc in the database', function () {
       it('should look for the doc in the database', function () {
         this.db.docOps.findOne
         this.db.docOps.findOne
           .calledWith(
           .calledWith(
-            { doc_id: ObjectId(this.docId) },
+            { doc_id: new ObjectId(this.docId) },
             {
             {
               projection: { version: 1 },
               projection: { version: 1 },
             }
             }
@@ -376,7 +376,7 @@ describe('MongoManager', function () {
 
 
   describe('checkRevUnchanged', function () {
   describe('checkRevUnchanged', function () {
     this.beforeEach(function () {
     this.beforeEach(function () {
-      this.doc = { _id: ObjectId(), name: 'mock-doc', rev: 1 }
+      this.doc = { _id: new ObjectId(), name: 'mock-doc', rev: 1 }
     })
     })
 
 
     it('should call the callback when the rev has not changed', function (done) {
     it('should call the callback when the rev has not changed', function (done) {
@@ -397,7 +397,7 @@ describe('MongoManager', function () {
 
 
     it('should return a value error if incoming rev is NaN', function (done) {
     it('should return a value error if incoming rev is NaN', function (done) {
       this.db.docs.findOne = sinon.stub().callsArgWith(2, null, { rev: 2 })
       this.db.docs.findOne = sinon.stub().callsArgWith(2, null, { rev: 2 })
-      this.doc = { _id: ObjectId(), name: 'mock-doc', rev: NaN }
+      this.doc = { _id: new ObjectId(), name: 'mock-doc', rev: NaN }
       this.MongoManager.checkRevUnchanged(this.doc, err => {
       this.MongoManager.checkRevUnchanged(this.doc, err => {
         err.should.be.instanceof(Errors.DocRevValueError)
         err.should.be.instanceof(Errors.DocRevValueError)
         done()
         done()
@@ -435,8 +435,8 @@ describe('MongoManager', function () {
       it('updates Mongo', function () {
       it('updates Mongo', function () {
         expect(this.db.docs.updateOne).to.have.been.calledWith(
         expect(this.db.docs.updateOne).to.have.been.calledWith(
           {
           {
-            _id: ObjectId(this.docId),
-            project_id: ObjectId(this.projectId),
+            _id: new ObjectId(this.docId),
+            project_id: new ObjectId(this.projectId),
             rev: this.archivedDoc.rev,
             rev: this.archivedDoc.rev,
           },
           },
           {
           {
@@ -466,8 +466,8 @@ describe('MongoManager', function () {
       it('sets ranges to an empty object', function () {
       it('sets ranges to an empty object', function () {
         expect(this.db.docs.updateOne).to.have.been.calledWith(
         expect(this.db.docs.updateOne).to.have.been.calledWith(
           {
           {
-            _id: ObjectId(this.docId),
-            project_id: ObjectId(this.projectId),
+            _id: new ObjectId(this.docId),
+            project_id: new ObjectId(this.projectId),
             rev: this.archivedDoc.rev,
             rev: this.archivedDoc.rev,
           },
           },
           {
           {

+ 19 - 19
services/docstore/test/unit/js/RangeManagerTests.js

@@ -31,10 +31,10 @@ describe('RangeManager', function () {
 
 
   describe('jsonRangesToMongo', function () {
   describe('jsonRangesToMongo', function () {
     it('should convert ObjectIds and dates to proper objects', function () {
     it('should convert ObjectIds and dates to proper objects', function () {
-      const changeId = ObjectId().toString()
-      const commentId = ObjectId().toString()
-      const userId = ObjectId().toString()
-      const threadId = ObjectId().toString()
+      const changeId = new ObjectId().toString()
+      const commentId = new ObjectId().toString()
+      const userId = new ObjectId().toString()
+      const threadId = new ObjectId().toString()
       const ts = new Date().toJSON()
       const ts = new Date().toJSON()
       return this.RangeManager.jsonRangesToMongo({
       return this.RangeManager.jsonRangesToMongo({
         changes: [
         changes: [
@@ -56,18 +56,18 @@ describe('RangeManager', function () {
       }).should.deep.equal({
       }).should.deep.equal({
         changes: [
         changes: [
           {
           {
-            id: ObjectId(changeId),
+            id: new ObjectId(changeId),
             op: { i: 'foo', p: 3 },
             op: { i: 'foo', p: 3 },
             metadata: {
             metadata: {
-              user_id: ObjectId(userId),
+              user_id: new ObjectId(userId),
               ts: new Date(ts),
               ts: new Date(ts),
             },
             },
           },
           },
         ],
         ],
         comments: [
         comments: [
           {
           {
-            id: ObjectId(commentId),
-            op: { c: 'foo', p: 3, t: ObjectId(threadId) },
+            id: new ObjectId(commentId),
+            op: { c: 'foo', p: 3, t: new ObjectId(threadId) },
           },
           },
         ],
         ],
       })
       })
@@ -109,10 +109,10 @@ describe('RangeManager', function () {
     })
     })
 
 
     return it('should be consistent when transformed through json -> mongo -> json', function () {
     return it('should be consistent when transformed through json -> mongo -> json', function () {
-      const changeId = ObjectId().toString()
-      const commentId = ObjectId().toString()
-      const userId = ObjectId().toString()
-      const threadId = ObjectId().toString()
+      const changeId = new ObjectId().toString()
+      const commentId = new ObjectId().toString()
+      const userId = new ObjectId().toString()
+      const threadId = new ObjectId().toString()
       const ts = new Date().toJSON()
       const ts = new Date().toJSON()
       const ranges1 = {
       const ranges1 = {
         changes: [
         changes: [
@@ -145,18 +145,18 @@ describe('RangeManager', function () {
       this.ranges = {
       this.ranges = {
         changes: [
         changes: [
           {
           {
-            id: ObjectId(),
+            id: new ObjectId(),
             op: { i: 'foo', p: 3 },
             op: { i: 'foo', p: 3 },
             metadata: {
             metadata: {
-              user_id: ObjectId(),
+              user_id: new ObjectId(),
               ts: new Date(),
               ts: new Date(),
             },
             },
           },
           },
         ],
         ],
         comments: [
         comments: [
           {
           {
-            id: ObjectId(),
-            op: { c: 'foo', p: 3, t: ObjectId() },
+            id: new ObjectId(),
+            op: { c: 'foo', p: 3, t: new ObjectId() },
           },
           },
         ],
         ],
       }
       }
@@ -194,7 +194,7 @@ describe('RangeManager', function () {
 
 
     return describe('with changes', function () {
     return describe('with changes', function () {
       it('should return true when the change id changes', function () {
       it('should return true when the change id changes', function () {
-        this.ranges_copy.changes[0].id = ObjectId()
+        this.ranges_copy.changes[0].id = new ObjectId()
         return this.RangeManager.shouldUpdateRanges(
         return this.RangeManager.shouldUpdateRanges(
           this.ranges,
           this.ranges,
           this.ranges_copy
           this.ranges_copy
@@ -202,7 +202,7 @@ describe('RangeManager', function () {
       })
       })
 
 
       it('should return true when the change user id changes', function () {
       it('should return true when the change user id changes', function () {
-        this.ranges_copy.changes[0].metadata.user_id = ObjectId()
+        this.ranges_copy.changes[0].metadata.user_id = new ObjectId()
         return this.RangeManager.shouldUpdateRanges(
         return this.RangeManager.shouldUpdateRanges(
           this.ranges,
           this.ranges,
           this.ranges_copy
           this.ranges_copy
@@ -226,7 +226,7 @@ describe('RangeManager', function () {
       })
       })
 
 
       it('should return true when the comment id changes', function () {
       it('should return true when the comment id changes', function () {
-        this.ranges_copy.comments[0].id = ObjectId()
+        this.ranges_copy.comments[0].id = new ObjectId()
         return this.RangeManager.shouldUpdateRanges(
         return this.RangeManager.shouldUpdateRanges(
           this.ranges,
           this.ranges,
           this.ranges_copy
           this.ranges_copy