September 2018
Beginner to intermediate
192 pages
4h 37m
English
This class performs operations that are needed to store a purchase: lookup the customer and product, create and save the purchase document, and then update the purchase history array in the customer document:
namespace Application; use Throwable; use MongoDB\Model\BSONDocument; class Add extends Base {
The first method performs a customer lookup by name. Note that we define a projection which represents a limited subset of all customer information. This becomes the base customer document which will later be embedded in the purchase document:
public function findCustomerByName($name) { $options = [ 'projection' => [ '_id' => 1, 'name' => 1, 'state_province' => 1, 'country' => 1, 'balance' => 1, 'purch_history' => 1 ] ]; $result ...Read now
Unlock full access