0
檢索多個條目
場景:從2個集
我有兩個JSON的存儲在以下格式的MongoDB的:(他們是Yelp的教育)
JSON1:(Yelp的業務)
{
"business_id":"tl9XIP5trlkcuSfTQqe5jg",
"full_address":"632 N Estrella Pkwy\nGoodyear, AZ 85338",
"hours":{
},
"open":true,
"categories":[
"Fast Food",
"Restaurants"
],
"city":"Goodyear",
"review_count":6,
"name":"McDonalds",
"neighborhoods":[
],
"longitude":-112.39319500000001,
"state":"AZ",
"stars":2.0,
"latitude":33.453887000000002,
"attributes":{
"Take-out":true,
"Wi-Fi":"free",
"Drive-Thru":true,
"Alcohol":"none",
"Caters":false,
"Noise Level":"average",
"Takes Reservations":false,
"Delivery":false,
"Parking":{
"garage":false,
"street":false,
"validated":false,
"lot":false,
"valet":false
},
"Has TV":true,
"Outdoor Seating":false,
"Attire":"casual",
"Waiter Service":false,
"Accepts Credit Cards":true,
"Good for Kids":true,
"Price Range":1
},
"type":"business"
}
JSON2:(評論)
{
"votes":{
"funny":0,
"useful":0,
"cool":0
},
"user_id":"pNvoNTu6U7Ek2w_xe4QO-w",
"review_id":"qyUlYgt68wexC_6qLL0sKg",
"stars":1,
"date":"2012-03-12",
"text":"The worst McDonalds I've ever been to. The burgers are barely room temp and the cheese is barely melted on them even though they microwave them! Which is disgusting as it is. Chicken nuggets are always old and greasy (and again never hot enough). Filet o fish cold and gross..and either unmelted cheese or cheese that was nuked so long that it is like plastic. Nasty. I've never had a decent meal here. Haven't gone in months. Gross.",
"type":"review",
"business_id":"tl9XIP5trlkcuSfTQqe5jg"
}
他們都有相同business_id
問題陳述:我如何寫一個查詢,這樣我可以獲取「類別」:「快餐」,並在同一時間獲得評論?
我能夠檢索一個而不是評論。請給出意見!
代碼:
System.out.println("Fast Food Restaurants");
BasicDBObject rest = new BasicDBObject();
rest.put("categories", "Indian");
DBCursor cursor2 = table.find(rest);
while(cursor2.hasNext()){ //display all fast food restaurants
System.out.println(cursor2.next());
}
我怎麼能顯示來自其他JSON的收視率?
謝謝你的時間!
Repped。謝謝。我怎樣才能做到多個步驟?我一直在撓我的頭一陣子,無法走出這個循環! :( –
我已編輯帖子保存格式 – hellboy
哇..我會試試這個並回復給你!!謝謝! –