我想只打印相关字段的值(name
)。它现在做的是打印以下内容。
nameHOSTA
nameHOSTB
我希望它打印
HOSTA
HOSTB
查询...
puts collection.find({"environment_name" => role, "type" => "TF"}, {:fields => {"_id" => 0, "name" =>
1}}).to_a
答案 0 :(得分:4)
我认为这样的事情应该让你想要你想要的东西:
collection.find({"environment_name" => role, "type" => "TF"}, {:fields => {"_id" => 0, "name" =>1}}).each { |item|
puts item['name']
}