我已經使用shell命令在Mongodb集合「clicklog」中爲json文件建立了索引。下面是我的shell命令的結果:如何使用MongoDB shell從MongoDB集合獲取特定字段?
db.clicklogs.find().pretty()
輸出:
{
"_id" : ObjectId("58fe78dcfbe21fa7896552e8"),
"preview" : false,
"offset" : 0,
"result" : {
"search_term" : "484797",
"request_time" : "Sat Apr 01 23:58:49 -0400 2017",
"request_ip" : "127.0.0.1",
"stats_type" : "clickstats",
"upi" : "66024330304",
"unit" : "CITCS",
"job_title" : "IT Engineer",
"vpu" : "ICR",
"organization" : "73",
"location" : "MH",
"city" : "San Diego",
"country" : "USA",
"title" : "TOM",
"tab_name" : "People-Tab",
"page_name" : "PEOPLE",
"result_number" : "1",
"page_num" : "0",
"session_id" : "14e88b44576ad4fdc035bc41529762ad1",
"total_results" : "1",
"_raw":"request_time=Sat Apr 01 23:58:49 -0400 2017,request_ip=127.0.0.1,application=Search,stats_type=clickstats,upi=660243301304,unit=CITCS,job_title=IT Assistant, Client Services,vpu=ICR,location=DHAKA, BANGLADESH (IFC),organization=73,city=Dhaka,country=BANGLADESH,city_code=,search_term=484797,title= Tom,url=http://isearch.worldbank.org/skillfinder/ppl_profile_new/000484797,tab_name=People-Tab,page_name=PEOPLE,result_number=1,page_num=0,filter=qterm=484797,total_results=1,app_environment=production,log_version=1.0,session_id=4e88b44576ad4fdc035bc41529762ad1",
"_time":"2017-04-01T23:58:49.000-0400"
}
}
{"_id" : ObjectId("58fe78dcfbe21fa7896552e9"),
"preview" : false,
"offset" : 0,
"result" : {
"search_term" : "demo",
"request_time" : "Sat Apr 01 23:58:49 -0400 2017",
"request_ip" : "127.0.0.1",
....
"time":"2017-04-01T23:58:49.000-0400"
}
}
對於每一個JSON文件,我想只得到幾個字段(ID,搜索關鍵詞,合衆國際社,PAGE_NAME,會話ID, url(在_raw下))。是否有可能使用mongo shell命令並將結果文檔存儲在新集合中?任何幫助表示讚賞。
你的mongodb版本是什麼? – Veeram
我在最新版本3.4.4 – Rose