-
Notifications
You must be signed in to change notification settings - Fork 1
/
get feed partially working query.txt
54 lines (54 loc) · 1.37 KB
/
get feed partially working query.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
Post.aggregate([
{
$match:{
createdBy:ObjectId(userId)
}
},
{
$lookup:{
from:'profiles',
localField:'createdBy',
foreignField:'user',
as:'profile'
}
},
{
$unwind:'$profile'
},
{
$group:{
_id:'$_id',
text:{$first:'$text'},
images:{$first:'$images'},
tags:{$first:'$tags'},
createdBy:{$first:'$createdBy'},
createdDate:{$first:'$createdDate'},
like:{$first:'$like'},
friends:{$first:'$profile.friends'}
}
},
{
$unwind:'$friends'
},
{
$lookup:{
from:'posts',
localField:'friends.user',
foreignField:'createdBy',
as:'posts'
}
},
{
$unwind:'$posts'
},
{
$group:{
_id:'$_id',
text:{$first:'$text'},
images:{$first:'$images'},
tags:{$first:'$tags'},
createdDate:{$first:'$createdDate'},
like:{$first:'$like'},
friendsposts:{$push:'$posts'}
}
}