0
votes

Say I have a mongoid document which has a field :pairs with the type of hash. When I wan't to query on the hash like this:

Doc.where(:pairs=>{"field1"=>1})

I get results back because I have in pairs a field with value one. I also have values for more than 1. When I do the following, nil is returned:

Doc.where(:pairs=>{"field1"=>{"$gt"=>0}})

This doesn't seem to work, and I do have pairs with key field1 and values bigger than 0. Can anyone provide me info on why this doesn't work?

2

2 Answers

1
votes

Just try: Dco.where(:pairs.gt => 0)
For more detail mongoid querying see following link.
http://mongoid.org/en/mongoid/docs/querying.html

-1
votes
Doc.where('pairs.field1' => {"$gt"=>1})