hi,
does anyone have an idea, what’s the reason for missing data in my aggregation?
This is my pipeline:
[
{
$lookup: {
as: "resultcheck",
foreignField: "checkId",
from: "checks",
localField: "checkId",
},
},
{
$lookup: {
as: "resultDepartment",
foreignField: "DepId",
from: "department",
localField: "DepartmentId",
},
},
{
$unwind: {
path: "$X",
},
},
{
$unwind: {
path: "$X.X",
},
},
{
$unwind: {
path: "$resultDepartment",
},
},
{
$unwind: {
path: "$resultcheck",
},
},
{
$match: {
$and: [
{
"X.X.TotalType":
"Forecast",
"X.X.FiscalYear":
{
$ne: null,
},
},
],
},
},
{
$project: {
_id: true,
number: "$Number",
responsible: "$rResponsible",
calendarMonth: "$Period",
department: "$resultDepartment.Name",
finishDate: "$FinishDate",
xYear: "$X.X.Year",
year: "$Year",
level: "$Level",
check: "$resultcheck.check",
period: {
$switch: {
branches: [
{
case: {
$eq: ["$Period", 10],
},
then: 1,
},
{
case: {
$eq: ["$Period", 11],
},
then: 2,
},
{
case: {
$eq: ["$Period", 12],
},
then: 3,
},
{
case: {
$eq: ["$Period", 1],
},
then: 4,
},
{
case: {
$eq: ["$Period", 2],
},
then: 5,
},
{
case: {
$eq: ["$Period", 3],
},
then: 6,
},
{
case: {
$eq: ["$Period", 4],
},
then: 7,
},
{
case: {
$eq: ["$Period", 5],
},
then: 8,
},
{
case: {
$eq: ["$Period", 6],
},
then: 9,
},
{
case: {
$eq: ["$Period", 7],
},
then: 10,
},
{
case: {
$eq: ["$Period", 8],
},
then: 11,
},
{
case: {
$eq: ["$Period", 9],
},
then: 12,
},
],
},
},
title: "$Title",
type: "$X.X.TotalType",
value:
"$X.X.Value",
},
},
]
i’ve got from over 17k documents only 16k.
The original document contains a lot of objects with arrays inside the objects, which i resolve with unwind i.e.
Can someone help?
Kind Regards
LJ
PS: i have anonymized some parts of this code