1

RubyMongoDriverを使用しています。

  @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 に答える