Hi! So, I’m trying to fetch posts along with their creators and the likes of the post.
But I cannot seem to get any result for User (creator). The Post table contains a creator_id which is a pointer to the User table. I get all the results fine but the User data does not contain any attributes.
Here’s the code:
const Post = Moralis.Object.extend("Post")
const query = new Moralis.Query(Post)
query.descending("created_at")
query.limit(20)
query.select("name", "thumbnail_url", "creator_id.username", "creator_id.avatar", "likes")
const pipeline = [
{
lookup: {
from: "likes",
localField: "_id",
foreignField: "pl_post_id",
as: "likes"
}
}
];
const result = await query.aggregate(pipeline, {useMasterKey: true})
So, using this code; I do get the expected result, but I can’t seem to get the User table’s attribute (as you can see in the above image, I only get the objectId and none of the other attributes).
P.s: I have tried specifying the only creator_id in the select field or all the fields too. Normally without the use of aggregate; I can get the result of the post along with its creator using .find({useMasterKey: true}) but It does not work with aggregate.
Thank you for your precious time!