Sfoglia il codice sorgente

[misc] run the codemod for moving mongo projections into options

Jakob Ackermann 6 anni fa
parent
commit
b37e27f023

+ 11 - 3
services/docstore/app/js/MongoManager.js

@@ -26,7 +26,9 @@ module.exports = MongoManager = {
         _id: ObjectId(doc_id.toString()),
         project_id: ObjectId(project_id.toString())
       },
-      filter,
+      {
+        projection: filter
+      },
       callback
     )
   },
@@ -39,7 +41,11 @@ module.exports = MongoManager = {
     if (!options.include_deleted) {
       query.deleted = { $ne: true }
     }
-    db.docs.find(query, filter).toArray(callback)
+    db.docs
+      .find(query, {
+        projection: filter
+      })
+      .toArray(callback)
   },
 
   getArchivedProjectDocs(project_id, callback) {
@@ -106,7 +112,9 @@ module.exports = MongoManager = {
         doc_id: ObjectId(doc_id)
       },
       {
-        version: 1
+        projection: {
+          version: 1
+        }
       },
       function (error, doc) {
         if (error != null) {

+ 15 - 4
services/docstore/test/unit/js/MongoManagerTests.js

@@ -60,7 +60,9 @@ describe('MongoManager', function () {
             _id: ObjectId(this.doc_id),
             project_id: ObjectId(this.project_id)
           },
-          this.filter
+          {
+            projection: this.filter
+          }
         )
         .should.equal(true)
     })
@@ -101,7 +103,9 @@ describe('MongoManager', function () {
               project_id: ObjectId(this.project_id),
               deleted: { $ne: true }
             },
-            this.filter
+            {
+              projection: this.filter
+            }
           )
           .should.equal(true)
       })
@@ -129,7 +133,9 @@ describe('MongoManager', function () {
             {
               project_id: ObjectId(this.project_id)
             },
-            this.filter
+            {
+              projection: this.filter
+            }
           )
           .should.equal(true)
       })
@@ -241,7 +247,12 @@ describe('MongoManager', function () {
 
       it('should look for the doc in the database', function () {
         return this.db.docOps.findOne
-          .calledWith({ doc_id: ObjectId(this.doc_id) }, { version: 1 })
+          .calledWith(
+            { doc_id: ObjectId(this.doc_id) },
+            {
+              projection: { version: 1 }
+            }
+          )
           .should.equal(true)
       })