我想用Ruby嘗試Mongo。我連接,選擇集合,我可以從MongoDB查詢數據。MongoDB + Ruby。如何訪問文檔屬性?
irb(main):049:0> coll.find_one({:x=>4})
=> #<BSON::OrderedHash:0x3fdb33fdd59c {"_id"=>BSON::ObjectId('4f8ae4d7c0111ba6383cbe1b'), "x"=>4.0, "j"=>1.0}>
irb(main):048:0> coll.find_one({:x=>4}).to_a
=> [["_id", BSON::ObjectId('4f8ae4d7c0111ba6383cbe1b')], ["x", 4.0], ["j", 1.0]]
但是,如何訪問propeties,當我檢索BSON哈希?我需要的是這樣的:
data.x
=> 4
to_hash方法使我有同樣BSON :: OrderedHash ... :(