Commit 8fe60f24 by Hxy Committed by GitHub

fix(dataset): export index and metadata columns in exportAll (#7436)

The schema-detection aggregate in exportAll builds its $match from teamId
(returned by authDataset as a string). find() casts the string to ObjectId,
but aggregate() does not schema-cast $match values, so the aggregation
matched zero documents. exportSchema became undefined, indexCount/hasMetadata
fell back to 0/false, and the CSV header collapsed to q,a.

Wrap teamId and dataset _ids in Types.ObjectId so the aggregate $match works.
dataset _ids are already ObjectId from .lean(), so that wrap is defensive.

Co-authored-by: Claude <noreply@anthropic.com>
parent 7b382e80
...@@ -10,6 +10,7 @@ import { ...@@ -10,6 +10,7 @@ import {
} from '@fastgpt/service/support/user/utils'; } from '@fastgpt/service/support/user/utils';
import { NextAPI } from '@/service/middleware/entry'; import { NextAPI } from '@/service/middleware/entry';
import { WritePermissionVal } from '@fastgpt/global/support/permission/constant'; import { WritePermissionVal } from '@fastgpt/global/support/permission/constant';
import { Types } from '@fastgpt/service/common/mongo';
import { readFromSecondary } from '@fastgpt/service/common/mongo/utils'; import { readFromSecondary } from '@fastgpt/service/common/mongo/utils';
import type { DatasetDataSchemaType } from '@fastgpt/global/core/dataset/type'; import type { DatasetDataSchemaType } from '@fastgpt/global/core/dataset/type';
import { sanitizeCsvField } from '@fastgpt/service/common/file/csv'; import { sanitizeCsvField } from '@fastgpt/service/common/file/csv';
...@@ -53,8 +54,8 @@ async function handler(req: NextApiRequest, res: NextApiResponse<any>) { ...@@ -53,8 +54,8 @@ async function handler(req: NextApiRequest, res: NextApiResponse<any>) {
}); });
const match = { const match = {
teamId, teamId: new Types.ObjectId(teamId),
datasetId: { $in: datasets.map((d) => d._id) } datasetId: { $in: datasets.map((d) => new Types.ObjectId(d._id)) }
}; };
const [exportSchema] = await MongoDatasetData.aggregate<ExportSchemaType>( const [exportSchema] = await MongoDatasetData.aggregate<ExportSchemaType>(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment