Skip to content

Commit

Permalink
Regaining lost backward compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
yuki-takei committed Jul 22, 2024
1 parent d60a9c2 commit d75907c
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions apps/app/src/server/service/search-delegator/aggregate-to-index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,32 @@ export const aggregatePipelineToIndex = (maxBodyLengthToIndex: number, query?: Q

// join Comment
{
// MongoDB 5.0 or later can use concise syntax
// https://www.mongodb.com/docs/v6.0/reference/operator/aggregation/lookup/#correlated-subqueries-using-concise-syntax
// $lookup: {
// from: 'comments',
// localField: '_id',
// foreignField: 'page',
// pipeline: [
// {
// $addFields: {
// commentLength: { $strLenCP: '$comment' },
// },
// },
// ],
// as: 'comments',
// },
$lookup: {
from: 'comments',
localField: '_id',
foreignField: 'page',
let: { pageId: '$_id' },
pipeline: [
{
$match: {
$expr: {
$eq: ['$page', '$$pageId'],
},
},
},
{
$addFields: {
commentLength: { $strLenCP: '$comment' },
Expand Down

0 comments on commit d75907c

Please sign in to comment.