flowen
flowen

Reputation: 536

getting user profile information from collection, MongoError: Unsupported projection option

After logging in with twitter in this case, I route the user to an edit form. There they fill in their info and I route them to template which views their own profile. I store the users data in Meteor.users.profile.

Console gives me the following error:

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

But have no clue how to continue or what this means..

The call:

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

The method:

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;
    }

});

the router:

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});
    }
});

The subscription:

// 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 helper:

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

Upvotes: 0

Views: 178

Answers (1)

tarmes
tarmes

Reputation: 15442

You need to do this instead:

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
        }
    });
});

Upvotes: 1

Related Questions