我有点问,有人对Ids提出反对的深层文件。 我想从物体Ids中提取每个推进剂的细节。 询问:
const result = await this.ticketsv2Model
.aggregate([
{
$match: query,
},
{
$sort: {
createdAt: -1,
},
},
...generateLookupStage( issues , issueId , [ _id , name ]),
...generateLookupStage( subissues , subIssueId , [ _id , name ]),
...generateLookupStage( tickettypes , typeId , [ _id , name ]),
...generateLookupStage( statustypes , statusId , [ _id , name ]),
...generateLookupStage( departments , assignedDepartment , [
_id ,
name ,
]),
...generateLookupStage( users , assignedTo , [
_id ,
extension ,
firstName ,
lastName ,
]),
...generateLookupStage( users , openedBy , [
_id ,
extension ,
firstName ,
lastName ,
]),
{
$unwind: $ticketLogs ,
},
...generateLookupStage( users , ticketLogs.userId , [
_id ,
firstName ,
lastName ,
extension ,
]),
...generateLookupStage( statustypes , ticketLogs.statusId , [
_id ,
name ,
]),
...generateLookupStage(
departments ,
ticketLogs.assignedDepartment ,
[ _id , name , number ],
),
...generateLookupStage( users , ticketLogs.assignedTo , [
_id ,
firstName ,
lastName ,
extension ,
]),
{
$group: {
_id: $_id ,
issueId: { $first: $issueId },
subIssueId: { $first: $subIssueId },
typeId: { $first: $typeId },
ticketId: { $first: $ticketId },
resolutionTime: { $first: $resolutionTime },
clientInfo: { $first: $clientInfo },
statusId: { $first: $statusId },
openedBy: { $first: $openedBy },
remarks: { $first: $remarks },
assignedTo: { $first: $assignedTo },
assignedDepartment: { $first: $assignedDepartment },
ticketLogs: {
$push: {
chatId: $ticketLogs.chatId ,
recordingId: $ticketLogs.recordingId ,
voiceMailRecordingId: $ticketLogs.voiceMailRecordingId ,
remarks: $ticketLogs.remarks ,
statusId: $ticketLogs.statusId ,
userId: $ticketLogs.userId ,
assignedTo: $ticketLogs.assignedTo ,
assignedDepartment: $ticketLogs.assignedDepartment ,
comments: $ticketLogs.comments ,
},
},
},
},
{
$project: {
createdAt: 1,
issueId: 1,
subIssueId: 1,
typeId: 1,
clientInfo: 1,
statusId: 1,
remarks: 1,
assignedDepartment: 1,
assignedTo: 1,
ticketLogs: 1,
ticketId: 1,
openedBy: 1,
_id: 1,
action: {
$switch: {
branches: [
{
case: {
$eq: [ $assignedTo._id , new Types.ObjectId(user)],
},
then: update ,
},
{
case: {
$and: [
{
$in: [ $assignedDepartment._id , userDepartments],
},
{ $eq: [{ $type: $assignedTo._id }, missing ] },
],
},
then: pick ,
},
],
default: view ,
},
},
},
},
])
.exec();
产生忽略成分是一种习惯功能,可进行考量(来自当地和安插;因为,[或许你希望从文件中产生效应]。 我的机票文件:
{
"_id": {
"$oid": "65b2143e5b239b78bc756a68"
},
"issueId": {
"$oid": "644e940200d3bd6ab311f1fb"
},
"subIssueId": {
"$oid": "644e94b100d3bd6ab311f216"
},
"typeId": {
"$oid": "65828ebea1726254da22e506"
},
"clientInfo": {
"clientId": "1231235645123",
"clientEmail": "[email protected]",
"clientPhone": "12233",
"clientName": "Arpan Dhakal",
"clientImage": "linkto.image",
"_id": {
"$oid": "65b2143e5b239b78bc756a69"
}
},
"statusId": {
"$oid": "658294ca9777467f6777802e"
},
"remarks": "Custom remarks here",
"assignedDepartment": {
"$oid": "658294a2aa8146af8fe85b50"
},
"ticketLogs": [
{
"chatId": "658294a2aa8146af8fe85b50",
"recordingId": "658294a2aa8146af8fe85b50",
"voiceMailRecordingId": "658294a2aa8146af8fe85b50",
"remarks": "Ticket Created",
"statusId": {
"$oid": "658294f1660cac3e3acda29a"
},
"userId": {
"$oid": "65af5d2e08a356fd82718d64"
},
"assignedTo": null,
"assignedDepartment": {
"$oid": "658294a2aa8146af8fe85b50"
},
"_id": {
"$oid": "65b2143e5b239b78bc756a6a"
},
"createdAt": {
"$date": "2024-01-25T07:56:46.778Z"
},
"updatedAt": {
"$date": "2024-01-25T07:56:46.778Z"
},
"comments": [
{
"comment": "hello world",
"createdAt": {
"$date": "2024-01-26T06:21:21.429Z"
},
"commentedBy": {
"$oid": "65af5d2e08a356fd82718d64"
},
"_id": {
"$oid": "65b34f61ec6cb747fc19f73a"
}
},
{
"comment": "hello world",
"createdAt": {
"$date": "2024-01-26T06:30:14.002Z"
},
"commentedBy": {
"$oid": "65af5d2e08a356fd82718d64"
},
"_id": {
"$oid": "65b35176cb2f23c9563c45f5"
}
},
{
"comment": "comment",
"commentedBy": {
"$oid": "644e06fc00d3bd6ab311d5fd"
},
"_id": {
"$oid": "65e99131c599c2d633062497"
},
"createdAt": {
"$date": "2024-03-07T10:04:33.007Z"
},
"updatedAt": {
"$date": "2024-03-07T10:04:33.007Z"
}
}
]
}
],
"ticketId": "T-55NNXUBW",
"openedBy": {
"$oid": "644e06fc00d3bd6ab311d5fd"
},
"createdAt": {
"$date": "2024-01-25T07:56:46.778Z"
},
"updatedAt": {
"$date": "2024-03-07T10:04:33.007Z"
},
"__v": 0,
"assignedTo": {
"$oid": "644e06fc00d3bd6ab311d5fd"
}
}
基本上,我的文件有机票记录仪,是机票记录仪文件的一系列物体。 每张票记录仪都有评论意见,这些评论是评论文件的一系列内容。 查询工作涉及打字用户、状况、部门每张票记录的细节。 现在,我想对每项评论的用户细节进行说明。 这些评论主张发表评论。 我想评论By显示评论的用户的信息。