kitchen-examples
kitchen-examples copied to clipboard
Join user collection
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
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"]
}
]
}
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"
]
}