Ruby on rails 3 轨道3和x2B;MongoDB:如何进行嵌套查询?

Ruby on rails 3 轨道3和x2B;MongoDB:如何进行嵌套查询?,ruby-on-rails-3,mongodb,mongodb-ruby,Ruby On Rails 3,Mongodb,Mongodb Ruby,我正在使用Ruby Mongo驱动程序 @surname = coll2.find("name" => {"surname" => "testing"}) 这不应该起作用吗?我没有结果 我有{“name”:{“姓氏”:“testing”}你的代码应该工作得很好 > coll2.insert({"name" => {"surname" => "testing"}) # => BSON::ObjectId('4dcb2e53abad691f62000002'

我正在使用Ruby Mongo驱动程序

  @surname = coll2.find("name" => {"surname" => "testing"})
这不应该起作用吗?我没有结果


我有
{“name”:{“姓氏”:“testing”}

你的代码应该工作得很好

> coll2.insert({"name" => {"surname" => "testing"})
# => BSON::ObjectId('4dcb2e53abad691f62000002')
> coll2.insert({"name" => {"surname" => "another"})
# => BSON::ObjectId('4dcb2e53abad691f62000003')
> coll2.find().count
# => 2
> coll2.find("name" => {"surname" => "testing"}).count
# => 1
> coll2.find("name" => {"surname" => "testing"}).first
# => {"_id"=>BSON::ObjectId('4dcb2e53abad691f62000002'), "name"=>{"surname"=>"testing"}} 

你的代码应该工作得很好

> coll2.insert({"name" => {"surname" => "testing"})
# => BSON::ObjectId('4dcb2e53abad691f62000002')
> coll2.insert({"name" => {"surname" => "another"})
# => BSON::ObjectId('4dcb2e53abad691f62000003')
> coll2.find().count
# => 2
> coll2.find("name" => {"surname" => "testing"}).count
# => 1
> coll2.find("name" => {"surname" => "testing"}).first
# => {"_id"=>BSON::ObjectId('4dcb2e53abad691f62000002'), "name"=>{"surname"=>"testing"}} 

我认为下面的方法也行

coll2.find("name.surname"=>"testing").first

我认为下面的方法也行

coll2.find("name.surname"=>"testing").first

对我来说,它只适用于花括号。就像这样:

col2.find({"name.surname": "testing"})

对我来说,它只适用于花括号。就像这样:

col2.find({"name.surname": "testing"})