Answer the question
In order to leave comments, you need to log in
How to check a user's likes for a post?
Tell me how to be and what to do?
There are three collections USERS/POSTS/LIKES
USERS
{
_id: ObjectID('...'),
name: 'String'
}
{
_id: ObjectID('...'),
url: 'String',
createdBy: 'String User Name'
}
{
_id: ObjectID('...'),
uid: 'String ObjectID POSTS',
owner: 'String ObjectID USERS'
}
Posts
.aggregate([
{
$match: {
public: true
}
},
{ $sort: { createdAt: -1 }},
{ $skip: offset },
{ $limit: 20 },
{
$lookup: {
from: 'users',
localField: 'createdBy', // Posts.createdBy
foreignField: 'name', // Users.name
as: 'owner'
}
}, {
$project: {
id: 1,
url: 1,
'owner.ava': 1,
'owner.name': 1
}
},
{ $unwind: '$owner' }
]).exec((e, data) => {
return c(e || ! data.length ? e || page.notFound : null, data)
});
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question