Hello there,
My first topic here So be patient, LoL.
db.getCollection(
'core.usersAttributes'
).aggregate(
[
{ $unwind: { path: '$attributes' } },
{ $unwind: { path: '$attributes.values' } },
{
$sort: { 'attributes.values.createdAt': -1 }
},
{
$group: {
_id: {
id: '$_id',
attribute: '$attributes.attribute'
},
user: { $first: '$user' },
attribute: {
$first: '$attributes.attribute'
},
value: {
$first: '$attributes.values.value'
},
createdAt: {
$first: '$attributes.values.createdAt'
}
}
},
{
$lookup: {
from: 'attributes',
localField: 'attribute',
foreignField: '_id',
as: 'attributeInfo'
}
},
{
$project: {
_id: '$_id.id',
user: 1,
attribute: {
id: '$attribute',
title: {
$arrayElemAt: [
'$attributeInfo.title.en',
0
]
},
value: '$value',
createdAt: '$createdAt'
}
}
},
{
$group: {
_id: '$_id',
user: { $first: '$user' },
attributes: { $push: '$attribute' }
}
}
],
{ maxTimeMS: 60000, allowDiskUse: true }
);
I need this query to work on the data API. So I converted it to:
{
"dataSource": "{{dataSource}}",
"database": "{{dataBase}}",
"collection": "core.userAttributes",
"pipeline": [
{ "$unwind": "$attributes" },
{ "$unwind": "$attributes.values" },
{ "$sort": { "attributes.values.createdAt": -1 } },
{
"$group": {
"_id": {
"id": "$_id",
"attribute": "$attributes.attribute"
},
"user": { "$first": "$user" },
"attribute": { "$first": "$attributes.attribute" },
"value": { "$first": "$attributes.values.value" },
"createdAt": { "$first": "$attributes.values.createdAt" }
}
},
{
"$lookup": {
"from": "attributes",
"localField": "attribute",
"foreignField": "_id",
"as": "attributeInfo"
}
},
{
"$project": {
"_id": "$_id.id",
"user": 1,
"attribute": {
"id": "$attribute",
"title": { "$arrayElemAt": ["$attributeInfo.title.en", 0] },
"value": "$value",
"createdAt": "$createdAt"
}
}
},
{
"$group": {
"_id": "$_id",
"user": { "$first": "$user" },
"attributes": { "$push": "$attribute" }
}
}
]
}
The endpoint I’m sending is working normally for other aggregation queries.
With this query, no error (200 response) is returned, as well as no document.
Could you help me find out what is wrong with my data API call?
Thanks in advance!