我正在尝试使用以下方法从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")
}
我的回归是一个空数组。这是检索记录的正确方法吗? 感谢
答案 0 :(得分:3)
您应该使用dot notation:
coll.find('data.session_id' => 'aaa')
答案 1 :(得分:-1)
试试这个
dni = coll.find({data: {session_id: "aaa"}}).to_a