Errata

MongoDB and PHP

Errata for MongoDB and PHP

Submit your own errata for this product.

The errata list is a list of errors and their corrections that were found after the product was released.

The following errata were submitted by our customers and have not yet been approved or disproved by the author or editor. They solely represent the opinion of the customer.

Color Key: Serious technical mistake Minor technical mistake Language or formatting error Typo Question Note Update

Version Location Description Submitted by Date submitted
PDF Page 2
3

Page 2 :

The core objective of the ORM is developer convenience. The core objective of an ORM
is developer convenience as they are built to translate the database's tables, rows, and
columns into your languages objects.

In page 23 working with arrays its a good point to make the user remember he wants to iterate through the cursor object , for print_r of cursor object is null and will wonder for a while.

$set = $addresses->find(
array( 'superpowers' => 'agility')
);
foreach($set as $doc) {
print_r($doc);
}

Though MongoCursor has been explained before :-), I was wondering why its not displaying after I gave a print_r( $set );

Some questions I felt in reading page 26 is

"If you want to retrieve only the slice itself and not the entire document, you can come pretty close by retrieving the _id and the slice"

print_r($addresses->findone(
array( 'first_name' => 'Peter', 'last_name' => 'Parker'),
array('_id' => 1, 'superpowers' => array('$slice' => 2)))
);

The above will give you

Array
(
[_id] => MongoId Object
(
[$id] => 4f2e1b9caa6a477739000000
)

[superpowers] => Array
(
[0] => agility
[1] => stamina
)

)

The above was the only example, but I was thinking something more

What will happen when _id is set to 0 like

print_r($addresses->findone(
array( 'first_name' => 'Peter', 'last_name' => 'Parker'),
array('_id' => 0, 'superpowers' => array('$slice' => 2)))
);

it returns

Array
(
[address] => 175 Fifth Ave
[city] => New York
[first_name] => Peter
[last_name] => Parker
[state] => NY
[superpowers] => Array
(
[0] => agility
[1] => stamina
)

[zip] => 10010
)

and what about _id when removed like

print_r($addresses->findone(
array( 'first_name' => 'Peter', 'last_name' => 'Parker'),
array('superpowers' => array('$slice' => 2)))
);

will return

Array
(
[_id] => MongoId Object
(
[$id] => 4f2e1b9caa6a477739000000
)

[address] => 175 Fifth Ave
[city] => New York
[first_name] => Peter
[last_name] => Parker
[state] => NY
[superpowers] => Array
(
[0] => agility
[1] => stamina
)

[zip] => 10010
)

Somethings like this are left to user to think why its so ?

Some example like 'Clark Kent' was never created, nor I remember whether he mentios to create new ones. It would have been a good idea to mention to insert new ones as the book teaches how to do it.

Indexing :


Page : 34

Creating Manual References

Creating manual references is as simple as storing a primary key of another document and using findOne to access it:

$post = array(
'title' => 'MongoDB and PHP',
'text' => 'MongoDB an PHP are like PB and J. Good alone, great together',
'author' => 'spf13'
);
$post2 = array(
'_id' => $id,
'title' => 'MongoDB, PHP and You',
'text' => 'Before MongoDB I felt so empty using PHP. Now I have a new lease on life',
'author' => 'spf13'
);

But how the $id comes ? These were some questions arises.

Suggestions :

Installing Mongo Driver is there , but atleast one installation in an OS was good for it just contains 64 page . May be Ubuntu is a good one. It doesn't need that much time too . Just add to /etc/apt/source.list and do an apt-get and its already documented in mongodb.org . So its easy .

Hari K T  Feb 13, 2012 
Printed Page 10
several found as i'm reading through

PROBLEMS WITH MONGODB & PHP BOOK:

p.10:
Add the following line to your php.ini configuration and you're good to go:
extension=mongo.so" to php.ini
should read:
extension=mongo.so

p.18:
These two options are exclusive. There is no way upsert multiple documents.
should read:
There is no way to upsert multiple documents.

p.20:
In our previous examples, when we queried we used the method findone, which retrieves one or zero documents.
should read:
we used the method findOne, which

p.21:
We will need to iterate over this object to access the data on contains:
should read:
to access the data it contains:

p.22:
$db->numbers->find()->limit(2)->skip(20)->sort(array('num'=> -1));
should read:
$results = $db->numbers->find()->limit(2)->skip(20)->sort(array( 'num' => -1 ));

p.23:
A good example of when this mixing of types may be useful is if you were writing a CMS system in which most articles have a single author
should read:
is if you were writing a CMS in which most articles


-=-=-=-

If you like, i can continue to submit errors as I continue to read the book.




Ben Coffin  Jul 09, 2013