1
Meteor.publishComposite('jobs', {
    find: function() {
        var user = null;
        if (this.userId) {
            user = Meteor.users.findOne(this.userId);

            if ( user && user.profile && user.profile.isAdmin ) {
                return Jobs.find({}, { sort: { createdAt: -1 }});
            } else if(user && user._id) {
                return Jobs.find({'createdBy': user._id});
            } 
        } else {
            return this.ready();
        }
    },
    children: [
        {
            find: function(job) {
                // Find post author. Even though we only want to return
                // one record here, we use "find" instead of "findOne"
                // since this function should return a cursor.
                return Meteor.users.find(
                    {
                    _id: job.createdBy
                },
                {
                    fields: {
                        'profile': 1, 
                        'createdAt': 1
                    }
                }

                );
            }
        }
    ]
});

这是我从meteor-publishComposite包中使用的代码。由于某种原因,我没有在我的订阅中获得个人资料。我可以让user.services出现,但不能user.profile

4

0 回答 0