@malik I’m wondering if it’s possible to get the User avatar.url() in a lookup / pipeline.
I can only get User like this is a pipeline, so straight from the db:
{
lookup: {
from: '_User',
localField: 'owner_of',
foreignField: 'accounts',
as: 'userItem'
}
},
Which only returns a limited set of actual db values and no access to methods because it’s not a Moralis object. There’s only a value ‘avatar’ which contains the filename:
avatar: "xxxxx_myavatar.png"
How would one append the full server url to use in the output?
For now I just append the User data directly to the results:
const queryResults = await query.aggregate(pipeline)
let results = []
if (queryResults) {
for (let i = 0; i < queryResults.length; i++) {
const userQuery = new Moralis.Query(Moralis.User)
userQuery.equalTo('accounts', queryResults[i].owner_of)
const userItem = await userQuery.first({useMasterKey:true})
if (userItem) {
queryResults[i].username = userItem.attributes.username
queryResults[i].avatar = userItem.attributes.avatar ? userItem.attributes.avatar.url() : null
}
results.push(queryResults[i])
}
}
return results
Fine for now, but prevents filtering and sorting on User (for example username) while still being able to use proper pagination with a $limit.
A solution is to do both, $lookup for sorting and filtering and appending the avatar._url to results with a Moralis.Query, spending a double call to the User table for each item.
So yes, not optimal. If you or someone knows a better way, let me know