【发布时间】:2014-05-07 12:34:54
【问题描述】:
场景:
我有两个 JSON 存储在 mongodb 中,格式如下:(它们来自 Yelp Educational)
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 的评分?
感谢您的宝贵时间!
【问题讨论】: