Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mongodb Mongo find()未返回嵌入文档_Mongodb_Mongodb Query_Pymongo - Fatal编程技术网

Mongodb Mongo find()未返回嵌入文档

Mongodb Mongo find()未返回嵌入文档,mongodb,mongodb-query,pymongo,Mongodb,Mongodb Query,Pymongo,我有一个具有以下结构的数据集。我给你看两份文件 { "business_id":"7vqhN9Ifq5DnaUkL3jyWGg", "full_address":"1322 Pleasant View Rd\nMiddleton, WI 53562", "hours":{ }, "open":true, "categories":[ "Active Life", "Golf Lessons", "Golf",

我有一个具有以下结构的数据集。我给你看两份文件

    {  
   "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"
}
这是另一份文件:

    {  
   "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"
}
我收集了80000份文件。对于每个文档,“属性”中的字段不同。我将如何归还所有具有“随意氛围”的文件。 这就是我所尝试的:

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

但是,我没有得到任何返回的数据。可能是什么问题?请帮助。

您正在将嵌入的文档属性.Ambience.casual字段的值存储为布尔值,而在查找文档时,您正在以字符串形式传递值,这就是为什么没有数据返回的原因

试试这个

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

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

您正在将嵌入的document attributes.Ambience.casual字段的值存储为布尔值,而在查找文档时,您正在将值作为字符串传递,这就是没有返回数据的原因

试试这个

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

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

您正在将其与字符串
“true”
进行比较。相反,您应该将其与布尔值
true
进行比较。尝试删除“true”周围的引号,例如
db.yelp\u dataset.find({“attributes.Ambience.casual”:true})
。将其与字符串
进行比较。相反,您应该将其与布尔值
true
进行比较。尝试删除“true”周围的引号,如
db.yelp\u dataset.find({“attributes.Ambience.casual”:true})