ruby mongo数据库查找方法

ruby mongo数据库查找方法,ruby,mongodb,Ruby,Mongodb,我正在尝试使用以下方法从mongodb检索记录: client = MongoClient.new("something.com",27017).db("big_data_api_development") coll = client.collection("dni_logs") dni = coll.find({"data" => {"session_id" => "aaa"}}).to_a 这是记录的样子: { "_id" : ObjectId("5272198be77989f

我正在尝试使用以下方法从mongodb检索记录:

client = MongoClient.new("something.com",27017).db("big_data_api_development")
coll = client.collection("dni_logs")
dni = coll.find({"data" => {"session_id" => "aaa"}}).to_a
这是记录的样子:

{
"_id" : ObjectId("5272198be77989f5be019323"),
"data" : {
    "dni_id" : "102329",
    "phone_number_id" : "10403",
    "phone_number_pool_id" : null,
    "master_node_id" : "686",
    "organizational_unit_id" : "896",
    "phone_number" : "888888888",
    "session_id" : "aaa",
    "ip_host" : "10.204.201.245",
    "browser" : "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:19.0) Gecko/20100101    Firefox/19.0 AlexaToolbar/alxf-2.17",
    "log_date" : "2013-04-08 19:02:03",
    "referring" : "google",
    "referring_type" : "Organic",
    "search_words" : "Not Available",
    "ref_params" : null,
    "custome_params" : null
},
"created_at" : ISODate("2013-04-09T00:02:03.000Z"),
"_keywords" : [ 
    "02", 
    "03", 
    "04", 
],
"updated_at" : ISODate("2013-10-31T08:49:15.227Z")
}
我的返回是一个空数组。这是检索记录的正确方法吗? 谢谢你试试这个

dni = coll.find({data: {session_id: "aaa"}}).to_a
您应该使用:

点表示法非常有效(使用gem Mongo版本2.4.3)
coll.find('data.session_id' => 'aaa')