Thanks for the tip but I don’t even know how to start using this package. I can see how the engine runs, but I can’t find the keys to start it up!
Apologies for the incoming rant, it’s not directed at you or anybody else here, but I’m at my wits end with this right now. I don’t think anything has ever made me this frustrated in my life and I’ve been programming for over 20 years (shell, php, jQuery etc - but totally new to full JS stacks and MongoDB).
The problem with a lot of third party Meteor packages that I have found, as a Meteor newb, is that the docs assume the user has a certain amount of knowledge about the base structure that the package is improving on or providing extra support for. This is not a slight on your package, I’m sure it does exactly what I need but the problem is that the whole Meteor/Mongo implementation is the worst documented (and community supported) of all of the aspects of Meteor. It’s almost like they don’t expect anybody to do anything remotely challenging with it, that people will be happy creating Todo lists or scoreboards until the cows come home.
It goes into no depth past the most basic of operations and trying to find help that isn’t older than about 3 or 4 years, and now largely irrelevant due to codebase changes or depreciated packages, on Stack Overflow is near impossible.
I’ve spent days and days trying to figure out to get an array of field values from one collection and use it to search and return the results of another, and it’s still not working. I must have tried a hundred different ways to date.
I’ve tried every package I could find, read as much as I could in the Meteor and Mongo docs and on forums and Stack, but the async nature of Meteor with Mongo is where I keep coming unstuck.
For example, this is my latest attempt where I’m having to use a method now (which I don’t want to do) as I just couldn’t get it to work with publish as this always returns undefined.
'new.get.followers': function(id, PER_PAGE = 5) {
var followers = [];
FollowersCollection.find({uid: id}, {limit: PER_PAGE}).forEach(function(u) { followers.push(u.fid) });
if (followers) {
var obj_ids = followers.map(function(follower) { return ObjectId(follower); });
return UserMeta.find({uid: {$in: obj_ids}});
}
return null;
}
But this throws errors in the server console :
Exception while invoking method 'new.get.followers' ReferenceError: ObjectId is not defined
I20180823-01:31:45.409(1)? at imports/collections/followers.js:66:58
What I’m trying to do in a nutshell…
- Pass an id into a function (preferably subscribe / publish functions) along with a limit (for pagination)
- Search the FollowersCollection using the id and matching it for every record where it finds the id in the uid field.
Example of a single FollowersCollection document :
{
"_id" : "vMPZi2ipGKf48RSiQ",
"uid" : "nskG2euomRcJEKBRs", //user ID
"fid" : "T4xtun25GJQYjrrzu" //followers user ID (we'll track him below)
}
- This should push the results of the fid field into the const followers array which represents each user ID that is following them. It would look something like this :
0: "T4xtun25GJQYjrrzu" //here he is
1: "gq33mc3Ws4agHrGtk"
2: "DCszsAuGfFXgLMi66"
3: "cBQ4bcs4H8EGF89ts"
4: "C8CoJKmFpHZjbuiHG"
- Then I map the followers array items to objects obj_ids
- Lastly I search the UserMeta collection and want to return an array of each followers meta data using all fields of each document where each item in obj_ids (each followers user ID) matches the uid field in this collection.
Example of a single UserMeta document :
{
"_id" : "aCru7hyhBdnnS7gSb",
"uid" : "T4xtun25GJQYjrrzu", //here he is again
"username" : "dave",
"avatar" : "15344635695b760e515b5655b760e515b5aa.jpg",
"updatedAt" : ISODate("2018-08-16T23:52:49.469Z"),
"name" : "Dave Masterson",
"country" : "UK"
}
If you can show me a way to do this using your package I will be eternally in your debt.