2013-03-29 111 views
1

當我運行此查詢到Rails控制檯:mongoid類型錯誤:密鑰必須是字符串或符號

1.9.3p286 :118 > cs = Conference.any_of({:schedule_cache => { :$elemMatch => { :start_date.gte => Date.parse('7 Mar 2013'), :end_date.lte => Date.parse('8 Mar 2013')}}}) 
1.9.3p286 :118 > cs.count 

我得到:

TypeError: keys must be strings or symbols 

回答

1

你試過用字符串鍵?

cs = Conference.any_of({'schedule_cache' => { '$elemMatch' => { 'start_date.gte' => Date.parse('7 Mar 2013'), 'end_date.lte' => Date.parse('8 Mar 2013')}}}) 
相關問題