Meteor使用過程中publications中发布的集合count有数据,route中订阅后,client端没有返回结果,mongol查看到的集合为空,代碼是這樣寫的:
if !this.userId
return cancel()
else
find: ->
options = {doctorId: this.userId}
if(patientId? and patientId )
options.patientId = patientId
if(event? and event )
options.event = event
console.log("options :: ",options)
Osi.Collection.History.find options,{limit: 20}
console.log "history count:: ", Osi.Collection.History.find(options,{limit: 20}).count()
最後發現,find會把最後一行當作結果返回,呵呵呵,真相後頓時覺得一萬隻羊駝奔騰而過,花了兩個小時踩過的坑,馬克一下。
正確的寫法是:
if !this.userId
return cancel()
else
find: ->
options = {doctorId: this.userId}
if(patientId? and patientId )
options.patientId = patientId
if(event? and event )
options.event = event
console.log("options :: ",options)
console.log "history count:: ", Osi.Collection.History.find(options,{limit: 20}).count()
Osis.Collection.History.find options,{limit: 20}
如果要查看記錄的條數,將count()放到上面,否則會把count擋住結果renturn回去。