kitchen-examples icon indicating copy to clipboard operation
kitchen-examples copied to clipboard

Join user collection

Open karambita opened this issue 9 years ago • 2 comments

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

karambita avatar Jun 09 '15 12:06 karambita

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"]
    }
  ]
}

perak avatar Jun 09 '15 12:06 perak

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"
    ]
}

ljack avatar Apr 09 '16 07:04 ljack