从集合中获取用户配置文件信息,MongoError:不支持的投影选项

时间:2015-03-13 11:51:03

标签: meteor

在这种情况下使用Twitter登录后,我将用户路由到编辑表单。在那里,他们填写他们的信息,我将他们路由到模板,查看他们自己的个人资料。我将用户数据存储在Meteor.users.profile中。

Console给出了以下错误:

Exception in queued task: MongoError: Unsupported projection option: name

但不知道如何继续或这意味着什么..

电话:

Meteor.call('update.user', profile, function(error, userId){
            if (error) {
                return alert(error.reason);             
            } else {
                Router.go('me', {_id: userId});
                // Router.go('me');
            }
        });

方法:

Meteor.methods({
    'update.user': function(postProfile) {
        // TODO: email validation?
        check(this.userId, String);
        check(postProfile, {
            preference: Match.Optional(String),
            gender: Match.Optional(String),
            name: Match.Optional(String),
            country: Match.Optional(String),
            city: Match.Optional(String),
            email: Match.Optional(String),
            story: Match.Optional(String)
        });

        Meteor.users.update(this.userId, {
            $set: {
                'profile.preference': postProfile.preference,
                'profile.gender': postProfile.gender,
                'profile.name': postProfile.name,
                'profile.country': postProfile.country,
                'profile.city': postProfile.city,
                'profile.email': postProfile.email,
                'profile.story': postProfile.story,
                'profile.firsttime': false
            }
        });

        return this.userId;
    }

});

路由器:

this.route('me', {
    template: 'profileView',
    path: '/me/:_id',
    waitOn: function() {
        return Meteor.subscribe('viewProfile', this.params.id);
    },
    data: function() {
        return Meteor.users.findOne({_id: this.params.id});
    }
});

订阅:

// Server-only code
Meteor.publish('currentUserData', function() {
    return Meteor.users.find({}, {
        fields : {
            'profiles': {
                'name': 1,
                'city': 1,
                'country': 1,
                'email': 1,
                'firsttime': 1,
                'gender': 1,
                'preference': 1,
                'story': 1
            }
        }
    });
});

模板助手:

Template.profileView.helpers({
    profile: function () {
        var user = Meteor.users.find({_id: this.params._id});
        return user;
    }
});

1 个答案:

答案 0 :(得分:1)

你需要这样做:

Meteor.publish('currentUserData', function() {
    return Meteor.users.find({}, {
        fields : {
            'profile.name': 1,
            'profile.city': 1,
            'profile.country': 1,
            'profile.email': 1,
            'profile.firsttime': 1,
            'profile.gender': 1,
            'profile.preference': 1,
            'profile.story': 1
        }
    });
});