My MongoDB data structure includes user profiles with friend request information. Here's an example:
{
_id: "someId",
profile: {
username: "oliv",
friendRequests: [
{ fromUserId: "anId", accepted: false, created: "someDate"},
{ fromUserId: "otherId", accepted: true, created: "otherDate"}
]
}
I'm trying to retrieve the user objects referenced in my logged-in user's friend requests. I attempted this query:
Meteor.users.find({_id: {$in: Meteor.user().profile.friendRequests.fromUserId}});
// Note: Meteor.users is the collection and Meteor.user() gets the current user
Unfortunately, it's not working, possibly due to the nested array structure.
Is there a way to instruct MongoDB to iterate through the fromUserId values?
Thank you