I use node-js sdk, code below, but the returned result do not contain searchSequenceToken
field,
export const getBlogList = async (
main: string,
category: string,
subcategory: string,
q: string,
searchToken: string
): Promise<{ data: any[]; more: boolean; nextToken?: string }> => {
try {
const pipeline: any[] = [];
const shouldConditions = [];
if (main || category || subcategory) {
shouldConditions.push({
text: {
query: [main, category, subcategory].filter(Boolean),
path: 'tags',
},
});
}
if (q) {
shouldConditions.push({
text: {
query: q,
path: ['tags', 'title', 'description', 'content'],
},
});
}
if (shouldConditions.length > 0) {
pipeline.push({
$search: {
index: "candy-bag-blogs",
compound: {
should: shouldConditions,
minimumShouldMatch: 1,
},
"sort": {
"score": {
"$meta": "searchScore", _id: 1
}
},
...(searchToken ? { searchAfter: [searchToken] } : {}),
},
});
}
pipeline.push({ $limit: pageSize });
pipeline.push({
$project: {
paginationToken: { $meta: 'searchSequenceToken' },
tags: 1,
title: 1,
description: 1,
},
});
const res = await mongoClient.db().collection('Blog').aggregate(pipeline).toArray();
console.log('111===res===', res);
const more = res.length >= pageSize;
return {
data: res,
more,
nextToken: res.length > 0 ? res[res.length - 1].searchToken : undefined,
};
} catch (error) {
console.error(error);
return { data: [], more: false, nextToken: undefined };
}
};