Browse Source

Merge pull request #8987 from weseek/fix/count-when-aggregation

fix: The $size query when aggregation to rebuild the index
Yuki Takei 1 year ago
parent
commit
dce991c023

+ 4 - 4
apps/app/src/server/service/search-delegator/aggregate-to-index.ts

@@ -88,7 +88,7 @@ export const aggregatePipelineToIndex = (maxBodyLengthToIndex: number, query?: Q
     },
     },
     {
     {
       $addFields: {
       $addFields: {
-        commentsCount: { $size: '$comments' },
+        commentsCount: { $size: { $ifNull: ['$comments', []] } },
       },
       },
     },
     },
 
 
@@ -103,19 +103,19 @@ export const aggregatePipelineToIndex = (maxBodyLengthToIndex: number, query?: Q
     },
     },
     {
     {
       $addFields: {
       $addFields: {
-        bookmarksCount: { $size: '$bookmarks' },
+        bookmarksCount: { $size: { $ifNull: ['$bookmarks', []] } },
       },
       },
     },
     },
 
 
     // add counts for embedded arrays
     // add counts for embedded arrays
     {
     {
       $addFields: {
       $addFields: {
-        likeCount: { $size: '$liker' },
+        likeCount: { $size: { $ifNull: ['$liker', []] } },
       },
       },
     },
     },
     {
     {
       $addFields: {
       $addFields: {
-        seenUsersCount: { $size: '$seenUsers' },
+        seenUsersCount: { $size: { $ifNull: ['$seenUsers', []] } },
       },
       },
     },
     },