【发布时间】:2023-01-25 10:30:32
【问题描述】:
我正在尝试将我的数据从我的网络应用程序导出到 Excel 工作表。我在 node js 中编写 next js 和 mongodb 是数据库。我正在从我的数据库中获取数据并将其运行到我的应用程序中,然后制作一张表格。该表似乎是按日期时间组织的。我希望它按名字或姓氏组织,然后当它导出到 excel 时它显示 _id 字段。它没有在我的应用程序中显示 _id 字段,但我认为是因为我在应用程序中没有列,但为什么它显示在我的 excel 工作表中。我是一名新开发人员,我刚刚从以前的开发人员那里接手了这个应用程序,没有一个老开发人员离开了。
我试图添加 $project 等,但是当我更改文件时我什么也没做,似乎没有任何作用。我能找到的唯一一个文件,它看起来像是在处理数据,如下所示:
export default async function handler(req,res){
//dbConnect(req);
let db = await dbConnect(req);
const Persons_Type_Information = db.models.Persons_Type_Information || db.model("Persons_Type_Information",personTypesInformationSchema)
const {method} = req;
const {rolecd} = req.query;
switch (method){
case "GET":
let resp = [];
try{
let responses = await Persons_Type_Information.aggregate([
{ $match: {
$expr: {
$and: [
{$eq: [{
$dateToString: {
date: {
$subtract: [
new Date(),
0
]
},
format: '%Y-%m-%d'
}
},
{$dateToString: {
date: '$pti_signed_in_date',
format: '%Y-%m-%d'
}
}]},
{$or: [
{$eq: [
"$pt_type",
"Employee"
]},
{$eq: [
"$pt_type",
"Contractor"
]}
]}
]
},
} },
{ $group:
{
_id: {$cond: {
'if': {
$eq: [
'$pti_visiting_location',
''
]
},
then: 'Employee',
'else': '$pti_visiting_location'
}},
count: {
$sum: {
$cond: {
'if': {
$ne: [
'$pti_signed_in_date',
''
]
},
then: 1,
'else': 0
}
}
}
},
}
]);
return res.json({
// data: JSON.parse(JSON.stringify(resp)),
data : JSON.parse(JSON.stringify(responses)),
success: true
}),
console.log(res);
}catch(error){
return res.send({
data : new Error(error).message,
success: false
})
}
default:
我找错地方了吗?我觉得这是正确的地方
【问题讨论】:
标签: javascript node.js mongodb express mongoose