0

MongoMapper を使い始めたばかりで、mongomapper.com の「ガイド」に従っていますが、データベースにクエリを実行すると、予期しない結果が得られます。結果は次のとおりです。

#<User:0x000000028d5070>
#<User:0x000000028d45a8>
#<User:0x000000029ec148>
#<User:0x000000029eb928>

私のコード:

require "mongo_mapper"
MongoMapper.connection = Mongo::Connection.new('localhost', 27017)
MongoMapper.database = "mydb"

class User
  include MongoMapper::Document

  key :name, String
  key :age,  Integer

  many :hobbies
end


class Hobby
  include MongoMapper::EmbeddedDocument

  key :name,    String
  key :started, Time
end


user = User.new(:name => 'Brandon')
user.hobbies.build(:name => 'Programming',
  :started => 10.years.ago)

user.save!

puts User.where(:name => 'Brandon').all

.where 部分の後に .first などのさまざまなものを使用してみましたが、それでも同じ結果、または Plucky::Query オブジェクトが得られます。

4

1 に答える 1

1

行は次のようになっているはずです。

puts User.where(:name => 'Brandon').first.name
于 2012-07-16T13:40:28.170 に答える