Something has been bothering meā¦
So far Iāve been working around it, like a few other posts I see on the forum like:
When I query a table that has a User Pointer, I canāt figure out how to get out the attributes on the cloud side.
const query = new Moralis.Query('SoldItems')
return await query.find({useMasterKey:true})
This will return the Pointer like:
"User":{"__type":"Pointer","className":"_User","objectId":"xxxxxxxxxx"}
And when I return the results it includes the full User object, which I donāt want. I want to select only the username for example.
When I do this:
const query = new Moralis.Query('SoldItems')
query.select('User.username')
return await query.find({useMasterKey:true})
It spits out this (using cloud logger):
"User":{"username":"Tester 1","createdAt":"2021-08-04T11:36:34.183Z","updatedAt":"2021-08-16T09:28:19.992Z","ACL":{"xxxx":{"read":true,"write":true}},"objectId":"xxx","__type":"Object","className":"_User"}
Pretty good, but I donāt want the ACL or dates, I just want username!
I tested this:
if (results) {
for (let i = 0; i < results.length; i++) {
items.push({
username: results[i].attributes.User.attributes.username,
username2: results[i].attributes.User.get('username'),
attributes: results[i].attributes.User.attributes,
user: results[i].attributes.User,
user2: results[i].get('User').attributes.username,
user3: results[i].get('User').get('username'),
})
}
}
return items
Which outputs only:
What am I missing here for parsing the User pointer?
Also in an aggregate pipeline itās a struggle.
(pointer is called buyerUser in my db but I call it User here for the example)