coffeescript - collection.find "fields" option interfere with "selector" argument -


i'd publish online users list clients, , exclude 'username' properties due security reasons. have following server side publish:

meteor.publish 'onlineusers', ->     users = meteor.users.find         "services.resume.logintokens.0":             $exists: true 

and works fine, producing following output:

console.log users.fetch()  >> [{         id: 'kfney2anhwzc4w4zx',        createdat: fri jan 31 2014 20:04:40 gmt+0400 (msk),        <...>    },     {   _id: 'tlnbhoqcex46v5l7s',        createdat: fri jan 31 2014 20:05:04 gmt+0400 (msk),        ...    }] 

but add "fields" option publish arguments, result empty list:

meteor.publish 'onlineusers', ->     users = meteor.users.find         "services.resume.logintokens.0":             $exists: true         fields:             username: true      console.log users.fetch()  >> [] 

so questions are:

  1. does "find" method query fields included result cursor?
  2. if it's so, best practice publish subset of fields each user?

upd: andrew mao noticed, had mistake while using coffeescript syntax. without preceeding comma fields option part of first argument object. correct method call should following:

meteor.users.find     "services.resume.logintokens.0":         $exists: true     ,          fields:             username: true 

you're using coffeescript , making mistake syntax. fields needs key in second argument find, not first one. 1 way can write is

meteor.publish 'onlineusers', ->     users = meteor.users.find {"services.resume.logintokens.0": {$exists: true}},         { fields:             { username: true }         } 

all curly braces optional above, , used show structure. can omit them once become more familiar coffeescript. all-important comma has between arguments somewhere.


Comments

Popular posts from this blog

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -