perak / kitchen-examples

Meteor Kitchen examples
164 stars 115 forks source link

Join user collection #19

Open karambita opened 9 years ago

karambita commented 9 years ago

Hi, Let's say we have companies collection and want to join users collection where the profile information is stored. Would it be possible to define joins with the users collection in the json file?

Great work btw. Thanks

perak commented 9 years ago

Hi,

I didn't try that, maybe it's possible... being super busy at the moment, can you try join and let me know what happens?

Maybe you can do something like:

{
  "name": "companies",
  "fields": [
    {
      "name": "company_name",
      "title": "Company name"
    },
    {
      "name": "userId",
      "join_collection": "users",
      "join_container": "user",
      "join_fields": ["profile"]
    }
  ]
}
ljack commented 8 years ago

Ah, users join didn't work for me either but it's doable using transform option:

queries/todos
{
    "transform": "function(doc) {doc.sharedToDoc={}; Meteor.users.find({ _id: doc.ownerId }).map(function(user) { doc.owner = user });  Meteor.users.find({ _id: {'$in': doc.sharedTo}}).map( function(user) {doc.sharedToDoc[user._id]=user; } ); console.log('doc=',doc);return doc;}",
    "sort": [
        "name"
    ]
}