Php Driver: documentation inconsistensy, undefined method and admingo not working

7 views
Skip to first unread message

diegomsana

unread,
Jun 1, 2009, 3:55:10 PM6/1/09
to mongodb-user
Ok, looks like i'm quickly becoming the most annoying user in this
forum :)

Playing with the php driver, i run into a few issues you may be aware
of, but anyway i'll report them here:

- All tutoriais in the php language center mentions i have to include
"mongo.php" file to call Mongo class methods. I guess this was
necessary in older versions but it's not now, since Mongo classes are
linked to php library. However, two classes which are not documented
at php.net/mongo (MongoAuth and MongoAdmin) still come in files i need
to place in the include path. You could do with these two classes what
you did to the others or clarify this in your documentation.

- I've downloaded Admingo but couldn't get it working "out of the
box", because the avaiable version still requires "mongo.php" and
doesn't include the files for MongoAuth/MongoAdmin classes. So i've
edited the source to fix this but then run into another problem: php
says method MongoUtil::dbcommand() is undefined. I double checked
that using the method_exists() function, which returns false for that
method. Guess this is a bug you need to fix.

- This one is a minor bug and it's not php-driver related: in the
mongo shell, typing "show users" as instructed by the help command
does not show the users in the current database. db.system.users.find
() does work though.

That's all.

Kristina Chodorow

unread,
Jun 1, 2009, 4:20:38 PM6/1/09
to mongod...@googlegroups.com
Ok, looks like i'm quickly becoming the most annoying user in this
forum :)

Not at all.  Thanks for letting me know, I lose track of all the stuff that needs updating!
 

- All tutoriais in the php language center mentions i have to include
"mongo.php" file to call Mongo class methods. 

Fixed the "Mongo.php" references in the tutorials.  I'll add some information about putting Admin.php and Auth.php on the include path. 

- I've downloaded Admingo but couldn't get it working "out of the
box", because the avaiable version still requires "mongo.php" and
doesn't include the files for MongoAuth/MongoAdmin  classes. 

I haven't worked on Admingo in a long while, I'd actually be surprised if that was the only thing wrong with it.  It will probably just be easier to use the database's web interface (localhost:28017 by default).

dbCommand very recently changed MongoDB::command().  Unfortunately, there is a delay on the PHP manual getting updated, so it's still there under MongoUtil.



- This one is a minor bug and it's not php-driver related: in the
mongo shell, typing "show users"  as instructed by the help command
does not show the users in the current database. db.system.users.find
() does work though.

 

I've filed a bug at http://jira.mongodb.org/browse/SERVER-87.

diegomsana

unread,
Jun 4, 2009, 6:38:24 PM6/4/09
to mongodb-user
Kristina,

I believe i've found another bug. When retrieving documents that
constains arrays of integers, php driver display crazy values for
those integers. This is the code i used to generate some random
integers and save into a document:

<?
$connection = new Mongo();
$db = $connection->selectDB("test");

$users = array ();
$keys = array ();

$collection = $db->selectCollection("integers");

for ($i = 0; $i < 10; $i++)
{
$u = mt_rand(0, 10000);
$users[] = $u;
}
$collection->insert(array("users"=>$users));

var_dump($collection->findOne());
?>

The var_dump() call in the last line outputs:
array(2) { ["_id"]=> object(MongoId)#7 (0) { } ["users"]=> array(10)
{ [0]=> int(140071768428512) [1]=> int(140071768432108) [2]=> int
(140071768429558) [3]=> int(140071768429072) [4]=> int
(140071768434267) [5]=> int(140071768429153) [6]=> int
(140071768425764) [7]=> int(140071768430107) [8]=> int
(140071768429055) [9]=> int(140071768431405) } }

However, a "db.integers.find()" on shell returns: {"_id" :
"4a284b5e674c3b197d373a73" , "users" :
[4064,7660,5110,4624,9819,4705,1316,5659,4607,6957]} which is the
expected values.

Using php 5.2.9 and driver 0.9.1 installed from pecl.

Kristina Chodorow

unread,
Jun 4, 2009, 6:53:17 PM6/4/09
to mongod...@googlegroups.com
I'm pretty sure that this has been fixed already.  Could you pull from http://github.com/mongodb/mongo-php-driver and try it again?

diegomsana

unread,
Jun 4, 2009, 7:09:16 PM6/4/09
to mongodb-user
Yes, it works now.

On 4 jun, 19:53, Kristina Chodorow <krist...@10gen.com> wrote:
> I'm pretty sure that this has been fixed already.  Could you pull fromhttp://github.com/mongodb/mongo-php-driverand try it again?

Kristina Chodorow

unread,
Jun 4, 2009, 7:10:34 PM6/4/09
to mongod...@googlegroups.com
Great!  Sorry for the inconvenience.

diegomsana

unread,
Jun 5, 2009, 8:57:09 AM6/5/09
to mongodb-user
No problem. Another quick question:

how do i issue an update using the $push modifier, is it implemented?

In mongo shell i'd do this: db.tags.u5144.update({_id:"howhose"},
{ $push : { posts: 400 } })

Could not figure out how to this through php.

On 4 jun, 20:10, Kristina Chodorow <krist...@10gen.com> wrote:
> Great!  Sorry for the inconvenience.
>
> On Thu, Jun 4, 2009 at 7:09 PM, diegomsana <diegodms...@gmail.com> wrote:
>
> > Yes, it works now.
>
> > On 4 jun, 19:53, Kristina Chodorow <krist...@10gen.com> wrote:
> > > I'm pretty sure that this has been fixed already.  Could you pull
> > fromhttp://github.com/mongodb/mongo-php-driverandtry it again?

Kristina Chodorow

unread,
Jun 5, 2009, 10:58:39 AM6/5/09
to mongod...@googlegroups.com
$push will work, but only if you have at least one element in the array to start out with.

Works:

$u5144->insert(array('_id' => "howhose", 'posts' => array(300)));
$u5144->update(array('_id'  => "howhose"), array( '$push' => array( 'posts' => 400 )));

Doesn't work:

$u5144->insert(array('_id' => "howhose", 'posts' => array()));
$u5144->update(array('_id'  => "howhose"), array( '$push' => array( 'posts' => 400 )));

The problem is, the database has an array type and an object type, which are only distinguished by the object type being allowed to have non-numeric keys.  As both of these types are represented by array() in PHP, the PHP driver takes a guess at which type you wanted.  For an empty array, it defaults to the database's object type, which you can't use $push with.

We're working on fixing this.

Wouter

unread,
Jul 9, 2009, 11:58:10 PM7/9/09
to mongodb-user
Any status update on this one?

You could always add a MongoEmptyArray object to the driver right?
Just anything that indicates an empty array will do I guess?!

Or you could create a MongoArray object, that implements Iterator /
ArrayAccess / Countable and denies all non-numeric keys, but that's a
lot more work :-).
> > > > fromhttp://github.com/mongodb/mongo-php-driverandtryit again?

Kristina Chodorow

unread,
Jul 10, 2009, 9:48:52 AM7/10/09
to mongod...@googlegroups.com
If you get the latest driver code, you can use MongoEmptyObj to insert
an object and array() to insert an empty array.

See http://us3.php.net/manual/en/class.mongoemptyobj.php.

So,

$u5144->insert(array('_id' => "howhose", 'posts' => array()));
$u5144->update(array('_id' => "howhose"), array( '$push' => array(
'posts' => 400 )));

should now work.

Wouter

unread,
Jul 10, 2009, 3:12:53 PM7/10/09
to mongodb-user
Great! Thanks!

On 10 jul, 15:48, Kristina Chodorow <krist...@10gen.com> wrote:
> If you get the latest driver code, you can use MongoEmptyObj to insert
> an object and array() to insert an empty array.
>
> Seehttp://us3.php.net/manual/en/class.mongoemptyobj.php.
Reply all
Reply to author
Forward
0 new messages