2012-09-11 82 views

回答

7

在蒙戈外殼:

db.pets.find({"foo.bar":{$gt:0}, another_attr:1}); 

在mongoid:

Pet.where(:'foo.bar'.gt => 0, :another_attr => 1) 
0

要找到一間酒吧值大於0所有的寵物,你可以在查詢中使用$ GT關鍵字。要訪問一個嵌套場(酒吧),你可以使用點符號:

db.pet.find({"foo.bar" : {$gt : 0}}) 

然後,還需要another_attr等於1,你可以添加其他的要求進入查詢:

db.pet.find({"foo.bar" : {$gt : 0} , another_attr : 1 }) 

您可以在這裏找到有關高級查詢的文檔:http://www.mongodb.org/display/DOCS/Advanced+Queries