简体   繁体   English

Mongo find()不返回嵌入式文档

[英]Mongo find() not returning for embedded documents

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. 我的收藏集中没有80000个文档。 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. 可能是什么问题?请帮忙。

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. 您正在存储嵌入的文档属性。Ambience.casual字段的值为Boolean,而在查找文档时,您正在将值作为字符串传递,这就是为什么没有数据返回的原因。

Try this 尝试这个

db.yelp_dataset.find({"attributes.Ambience.casual" :true});

instead of 代替

db.yelp_dataset.find({"attributes.Ambience.casual" :"true"});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM