Andreas Galster
Andreas Galster

Reputation: 415

find with sort on Meteor.users not working with profile.fieldname

I am trying to sort the user collection that I am returning. Specifically I want to sort a UNIX timestamp in profile.lastlogin. So I thought the code below would work but unfortunately meteor always throws errors of an unexpected token (the dot in profile.lastlogin). Any ideas what I am doing wrong? A normal sort on a normal collection without any fieldname.fieldname notatin works normal.

Template.profiles.helpers({
  filteredUsers: function () {
    return Meteor.users.find({
      $and: [
        {'_id': { $ne: Meteor.userId()} }, {'profile.interestone': Meteor.user().profile.interestone}
      ]
    }, {sort: {profile.lastlogin: 1}});
  }
});

Upvotes: 1

Views: 571

Answers (1)

tomsp
tomsp

Reputation: 1807

When using the dot notation to access the elements of an array or the fields of an embedded document you need to enclose your statement in quotes: 'some.thing'. In your case that would be

{sort: {'profile.lastlogin': 1}}

Upvotes: 3

Related Questions