Reputation: 405
I have a dataset with the following structure. I will show you two documents.
{
"business_id":"7vqhN9Ifq5DnaUkL3jyWGg",
"full_address":"1322 Pleasant View Rd\nMiddleton, WI 53562",
"hours":{ },
"open":true,
"categories":[
"Active Life",
"Golf Lessons",
"Golf",
"Fitness & Instruction"
],
"city":"Middleton",
"review_count":4,
"name":"Pleasant View Golf Course",
"neighborhoods":[
],
"longitude":-89.536493,
"state":"WI",
"stars":4.0,
"latitude":43.0875811,
"attributes":{
"Delivery":false,
"Good for Kids":true,
"Good For Groups":true,
"Good For":{
"dessert":false,
"latenight":false,
"lunch":false,
"dinner":false,
"brunch":false,
"breakfast":false
}
},
"type":"business"
}
Here is another document:
{
"business_id":"B0Vuwn6Hugc-0U5n31YBfg",
"full_address":"2550 Allen Blvd\nMiddleton, WI 53562",
"hours":{
"Monday":{
"close":"14:00",
"open":"06:00"
},
"Tuesday":{
"close":"14:00",
"open":"06:00"
},
"Friday":{
"close":"14:00",
"open":"06:00"
},
"Wednesday":{
"close":"14:00",
"open":"06:00"
},
"Thursday":{
"close":"14:00",
"open":"06:00"
},
"Sunday":{
"close":"13:00",
"open":"07:00"
},
"Saturday":{
"close":"14:00",
"open":"06:00"
}
},
"open":true,
"categories":[
"Bakeries",
"Food",
"American (Traditional)",
"Restaurants",
"Donuts"
],
"city":"Middleton",
"review_count":25,
"name":"C's Restaurant Bakery and Coffee Shop",
"neighborhoods":[
],
"longitude":-89.48674,
"state":"WI",
"stars":4.0,
"latitude":43.102896,
"attributes":{
"Take-out":true,
"Good For":{
"dessert":false,
"latenight":false,
"lunch":false,
"dinner":false,
"brunch":false,
"breakfast":true
},
"Noise Level":"average",
"Takes Reservations":false,
"Delivery":false,
"Ambience":{
"romantic":false,
"intimate":false,
"touristy":false,
"hipster":false,
"divey":false,
"classy":false,
"trendy":false,
"upscale":false,
"casual":true
},
"Parking":{
"garage":false,
"street":false,
"validated":false,
"lot":true,
"valet":false
},
"Has TV":false,
"Outdoor Seating":true,
"Attire":"casual",
"Alcohol":"none",
"Waiter Service":true,
"Accepts Credit Cards":true,
"Good for Kids":true,
"Good For Groups":true,
"Price Range":1
},
"type":"business"
}
I have aout 80000 documents in my collection. The fields in the "attribute" are not the same for each document. How will I return all the documents which have "a casual ambience". This is what I tried:
db.yelp_dataset.find({"attributes.Ambience.casual" :"true"})
However I do not get any returned data. What could be the problem?Please Help.
Upvotes: 0
Views: 73
Reputation: 985
You are storing embedded document attributes.Ambience.casual field's value as Boolean and while finding the document your are passing value as string that's why no data is returning.
Try this
db.yelp_dataset.find({"attributes.Ambience.casual" :true});
instead of
db.yelp_dataset.find({"attributes.Ambience.casual" :"true"});
Upvotes: 2