From f58db1724fe4ec28ea71a988d59337e29eb44eef Mon Sep 17 00:00:00 2001 From: istiopaxx Date: Thu, 30 Nov 2023 18:25:00 +0900 Subject: [PATCH] [Fix]: fix missing mysql id on search results --- .../recipe/mongo.recipe.repository.ts | 30 +++++++++++++------ 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/api/libs/recipe/src/repositories/recipe/mongo.recipe.repository.ts b/api/libs/recipe/src/repositories/recipe/mongo.recipe.repository.ts index efa49f8..f399cb7 100644 --- a/api/libs/recipe/src/repositories/recipe/mongo.recipe.repository.ts +++ b/api/libs/recipe/src/repositories/recipe/mongo.recipe.repository.ts @@ -119,16 +119,28 @@ export class MongoRecipeRepository { ? 'score' : textSearchRecipeDto.sort]: -1, }) - .project({ - _id: 0, - __v: 0, - recipe_raw_text: 0, - origin_url: 0, - recipe_steps: 0, - ingredient_requirements: 0, - }) .facet({ - recipes: [{ $skip: (page - 1) * limit }, { $limit: limit }], + recipes: [ + { + $addFields: { + mongo_id: '$id', + id: '$mysql_id', + }, + }, + { + $project: { + _id: 0, + __v: 0, + mysql_id: 0, + recipe_raw_text: 0, + origin_url: 0, + recipe_steps: 0, + ingredient_requirements: 0, + }, + }, + { $skip: (page - 1) * limit }, + { $limit: limit }, + ], count: [{ $count: 'count' }], }) .pipeline();