The problem is that MongoDB has no way to map record Categoryto record Ad. All he knows is that the record Adhas a field category_id, so it 'category.domain_id'always returns nothing. Dot notation inside queries only works for embedded documents, not links (which are still second-class citizens in MongoDB).
, , 2 :
category_ids = Category.where(:domain_id => domain.id).map(&:_id)
Ad.where(:category_id.in => category_ids)