parse-community / parse-server

Parse Server for Node.js / Express
https://parseplatform.org
Apache License 2.0
20.92k stars 4.78k forks source link

parse-server aggregate function returns empty object #7720

Open shash7976 opened 2 years ago

shash7976 commented 2 years ago

New Issue Checklist

Issue Description

$lookup is unable to grab the order object in spite of having an order that particular _id.

If I remove the $group and try $lookup directly I'm able to get the orderObject. (objectId: '$_p_order', and objectId:'$order' produces the same result)

EventTracking consists of order(pointer object), action(string)

Steps to reproduce

 const startingFrom = new Date(new Date() - 7 * 60 * 60 * 24 * 1000)
    const pipeline = [{
        match: {
            action: {
                $in: [
                    'Status updated from: Paid to Approved',
                    'Status updated from: Approved to Ready'
                ]
            },
            createdAt: { $gte: startingFrom }
        }
    },
    {
        group: {
            objectId: '$_p_order',
            date: {
                $addToSet: '$createdAt'
            },
        }
    },
    {
        addFields: {
            size: {
                $size: '$date'
            },
        }
    },
    {
        match: {
            size: {
                $eq: 2
            }
        }
    },
    {
        lookup: {
            'from': 'Order',
            'localField': 'objectId',
            'foreignField': '_id',
            'as': 'OrderObject'
        }
    }]
try {
        const query = new Parse.Query('EventTracking');
        const result = await query.aggregate(pipeline, master);
        console.log(result);
  } catch (error) {
      console.log(error);
}

Actual Outcome

  {
    date: [ [Object], [Object] ],
    size: 2,
    OrderObject: [],
    objectId: '9UpnIHbG8n'
  },

Expected Outcome

  {
    date: [ [Object], [Object] ],
    size: 2,
    OrderObject: [Object],
    objectId: '9UpnIHbG8n'
  },

Environment

Server

Database

Client

Logs

parse-github-assistant[bot] commented 2 years ago

Thanks for opening this issue!

mtrezza commented 2 years ago

Can you please complete the template and reduce the example to a minimum to reproduce the issue. It would also be helpful if you could open a PR with a failing test to demo the issue.