note 105467 deleted from mongocollection.insert by derick
| From: | derick@php.net | Date: | Thu, 29 Nov 2012 13:04:20 +0000 |
| Subject: | note 105467 deleted from mongocollection.insert by derick | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-192197@lists.php.net to get a copy of this message | ||
Note Submitter: rob at limeworks dot com dot au
----
There seems to be some odd behavior when writing a query then reading it back in very quickly. I
found it useful to ensure "safe" was set to true in order to stop random
"'MongoCursorException' with message 'couldn't send query: Broken
pipe'" messages all the time.
This is only in a development environment, so i'm not sure if it relates to our hardware, but
safe inserts fixed the issue 100%. Not even sure if it's the correct approach but it worked.
Note that the error doesn't seem to appear with small queries like below, but larger data it
does.
Example:
<?php
// connect
$m = new Mongo();
// select a database
$db = $m->comedy;
// select a collection (analogous to a relational database's table)
$collection = $db->cartoons;
// add a record
$obj = array( "title" => "Calvin and Hobbes", "author" =>
"Bill Watterson" );
$collection->insert($obj, array('safe'=>true));
// find everything in the collection
$cursor = $collection->find(array('author' => 'Bill Watterson'));
// iterate through the results
foreach ($cursor as $obj) {
echo json_encode($obj) . "<br />";
}
?>