1

我正在使用 Ruby Mongo 驱动程序。

  @surname = coll2.find("name" => {"surname" => "testing"})

这不应该工作吗?我没有得到任何结果。

我有 {"name" : { "surname" : "testing" }}

4

3 回答 3

1

我认为以下内容也可以

coll2.find("name.surname"=>"testing").first
于 2011-05-13T15:05:34.453 回答
0

您的代码应该可以完美运行。

> 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"}} 
于 2011-05-12T00:53:09.640 回答
0

对我来说,它只适用于大括号。像那样:

col2.find({"name.surname": "testing"})
于 2016-06-02T21:24:39.737 回答