How can you access a key in someone else's MongoDB User profile doc?


#1

I have groups that are upcoming events. The event/group has an array of user _id’s that are apart of the group. What I’d like on the group page is to have a list of the users first names. In each user upon creation I add their first name into their profile section of their user doc in Mongo. I’m having difficulty coming up with a way to access that variable in someone else’s database given their user _id. Is this possible or should I have it set up a different way?


#2

Make a publication + subscription, taking that array of ids and returning a query, containing sufficient data.
Be aware to only publish data you need - name/profile but not an entire document.

oh wait, i may have come into problem with understanding…
Are you saying that you try to operate with separate DB(IE different application or website)?
Or are you misspelling “database” while presuming “collection” or “document”?


#3

Oh sorry. I meant document. I think. There’s an array of user _id’s in a document for the group that is in a collection of all groups. I want to take those user _id’s and retrieve each users name through the accounts collection.


#4

I’ve never really done anything like this before so let me try to explain what I was thinking. I need a publish method on the server that will call Meteor.users.find(selector, options) where selector is {} because I was to publish all user’s names to anyone and options would be something like {profile: {firstName: 1}}. Then I’d subscribe to this publish method.

From here I have two questions. 1. Is this right or should this query be on the client side? 2. If this is correct so far then how do I write a client side method that accepts the id and get’s that users name?

If what I was proposing on the server side should actually be on the client side then I’m not sure how I restrict the data to only publishing the users name.


#5

I figured it out. You publish the entire collection on the server side and do the specific selection part on client side.