I'm new to mongo. I'm working on a small site for managing a food storage database. When I query the database for key:value pairs I'm getting results but when I need to find sub values, e.g. key:{key:value}, I get nothing. Here is my record structure;
> db.foodstore.find().pretty()
{
"_id" : ObjectId("5f5359676224333f529df761"),
"shelf" : "1",
"food" : "green beans",
"container" : {
"type" : "can",
"size" : "#10"
},
"dateIn" : "09/20",
"quantity" : "6"
}
Here is the php page code to query it:
<?php
require '../vendor/autoload.php';
$connection = new MongoDB\Client("mongodb://localhost:27017");
$collection = $connection->everything->foodstore;
echo "<div align='center'>";
$result = $collection->find([]);
echo "<table>";
foreach ($result as $entry){
echo "<tr><td>",$entry['shelf'],
"</td><td>",$entry['food'],
"</td><td>",$entry['dateIn'],
"</td><td>",$entry['container.size'],
"</td></tr>";
}
echo "</table></div>";
?>
The values for shelf,food, dateIn display fine but I cannot get container.size to show any value. Can anyone see where I'm screwing this up? Thanks in advance.
$entry['container.size']to$entry['container']['size']