2010-12-09 58 views
0

我試圖找出如何寫在一個複雜的查詢以下蒙戈查詢:{$or:[ {field:{$in:[X]}} , {field:{$size:0}}]}

目前我查詢生成器看起來像這樣:https://gist.github.com/735099

一切註釋掉是我曾嘗試和未能成功用。我能得到的最接近的是這query[:dma_codes] = {'$or' => [{'dma_codes' => {'$in' => [@bid_request[:geo][:dma]]}},{'dma_codes' => { '$size' => 0}}] }

我仍然得到以下錯誤:

Read error: #<NoMethodError: undefined method `name' for #<Mongo::OperationFailure: invalid operator: $or>> 
Mongo::OperationFailure - invalid operator: $or: 

有什麼我缺少關於構建此查詢?

回答

0

我想你想要這樣的:

query['$or'] = [{'dma_codes' => {'$in' => [@bid_request[:geo][:dma]]}},{'dma_codes' => { '$size' => 0}}] 

但我不知道紅寶石非常好。