瀏覽代碼

add countLikers method

takeru0001 5 年之前
父節點
當前提交
008fbb3200
共有 1 個文件被更改,包括 8 次插入0 次删除
  1. 8 0
      src/server/models/page.js

+ 8 - 0
src/server/models/page.js

@@ -389,6 +389,14 @@ module.exports = function(crowi) {
     }));
   };
 
+  pageSchema.statics.countLikers = async function(pageId) {
+    const result = this.aggregate()
+      .match({ page: { $in: pageId } })
+      .group({ _id: '$page', count: { $sum: 1 } });
+
+    return result;
+  };
+
   pageSchema.methods.isSeenUser = function(userData) {
     return this.seenUsers.includes(userData._id);
   };