Complex request with tunguska-reactive-aggregate $lookup

I’m trying to use https://github.com/robfallows/tunguska-reactive-aggregate with $lookup.
Is it possible to publish a reactive aggregate on such structure :

const ContactsSchema = new SimpleSchema({
  userId: {
    type: String,
    label: 'The ID of the user',
  },
  followedBy: {
    type: Array,
    label: 'informations about user\'s followers',
    optional: true,
    defaultValue: [],
  },
  'followedBy.$': UserSchema,
  blocked: {
    type: Array,
    label: 'informations about users blocked by user',
    optional: true,
    defaultValue: [],
  },
  'blocked.$': UserSchema,
...
const UserSchema = new SimpleSchema({
  userId: {
    type: String,
    label: 'userId of User',
  },
  since: {
    type: Date,
    label: 'date since last operation on record',
  },
});

Standard publish :

Meteor.publish("contacts.byId", userId => {
  return Contacts.find({ userId: userId });
});

I would like that the published Contacts resolves each userId in followedBy, blocked arrays as selected values of Meteor.users (username, avatar…) in the same way a graphQL request would do.

[ { 
userId: xxxx, 
followedBy: [ 
  { userId: u1, username: n1, avatar: a1, since: date1}, 
  { userId: u2, username: n2, avatar: a2, since: date2}...], 
blocked: [
  { userId: u3, username: n3, avatar: a3, since: date3}
]
}

I’m not familiar enough with $lookup to find a way to solve this, even know if it is possible or not.
Unfortunatly Rob doesn’t have enough available time to help and invited me to post here :wink:
Thank you

Not a lot of help here… :frowning: , so I started learning by myself with this excellent tooling and tutorial from Studio3T.
Here is the current status of my pipeline (not finished but in good way…)

[
{ $match: { userId: xxxx } },
{ $facet: {
   followedBy: [ 
    	{ 
            $unwind: {
    		path : "$followedBy",
    		preserveNullAndEmptyArrays : true 
	    }
    	},
    	{ 
            $lookup: {
    		from: "users",
   		localField: "followedBy.userId",
  		foreignField: "_id",
    		as: "userFollowedBy"
	    }
    	},
    	{ 
            $group: {
    	        _id: "$_id",
    		followedBy: {
                    $push: { user: "$userFollowedBy", since: "$followedBy.since"}
                }
    	    }
    	}
    ],
   blocked: [ 
    	{  .... same that above with blocked .... }
   ],
]

The output is not as expected, problems to solve :

  • filter userFollowedBy to have only the needed items (and not the full record of user : …blablabla… above)
  • get all the data from the contacts collection outside of group
  • simplify the double followedBy entry added by the $group
"followedBy" : [
        {
            "_id" : "LyeNvNBy6hiKxLKjQ", 
            "followedBy" : [
                {
                    "user" : [
                        {
                            "_id" : "RD7spqgeyPMMqfbko", 
                            "username" : "Humberto79", 
                            .... blablabla....
                        }
                    ], 
                    "since" : ISODate("2019-10-06T21:46:48.547+0000")
                }
            ]
1 Like