MongoRecord extensions

I released my MongoRecord extension which is still in early development. It’s work like i expected but haven’t fully tested. You can find it at:

http://www.yiiframework.com/extension/mongorecord/

I use it at my personal project at http://rserve.me

The reasons to release this extensions is to share it with the community and get feedback from you all. May be you can also help me to test this component.

tyohan

Great. I’ve started Mongo extension when 1.1 was just released but never finished it. Maybe you can find something useful in the source: http://code.google.com/p/yiiext/source/browse/trunk/app/extensions/yiiext/storages/mongo

hi,

let me know if you guys cook up something so I can feature it in a podcast!

keep it up,

–iM

Thanks imehesz, I just updated the documentation of this extension to show you how to use it. Check it here http://www.yiiframework.com/extension/mongorecord/

Good job.

Let me see if I can help.

In the docs you have this example:


$query=array('merchant_id'=>1,'');

ModelName::model()->findAll($query);

I believe the example is incorrect as it should be:


$query=array('query'=>array('merchant_id'=>1));

ModelName::model()->findAll($query);

Also will not work:




$query=array('_id=>'4c8377a88ead0ec468000000');

ModelName::model()->find($query);

We have to set a MongoID object to do this query:




$mongo_id = new MongoID("4c8377a88ead0ec468000000");

$query=array('_id=>$mongo_id);

ModelName::model()->find($query);

Keep up the good work.

Yes, it’s right. By default the criteria that passed to find() and findAll() method is using the same criteria that used on PHP mongo db driver. I think it’s better to implement the default and we can write findByPk method to pass _id without create new instance of MongoId object first.

@tyohan - GRRREAAT extension . Really.

Have you seen "Morph" http://code.google.com/p/mongodb-morph

It’s an activerecord mongodb implementation, that also supports relationships between collections.

It could be a nice addition to your code, isn’t it?

Regards…

Thanks, i just saw the library and it’s bring some of great features to implement on this extension. Thanks for advice, will try to implement some of it’s features at future development.

Thanks,

Thanks a lot for this extension! It’s a good start!

Is there any chance it will be compatible with CDataProvider soon (for e.g. to be used in ListWidget)

Yes, it could be. We can simulate this extension to provide any data that used by CDataProvider. Will add it to next features.

That would be awesome! :) Really looking forward to it!

Just found the extension and im trying it out. Looks great. Also in looking for this I found an active record someone made for mongo already here:

so im not sure if you could use some of the info for mongoRecord or if that will even work for yii. anyhow i have a question. In using mongo record, i see many thing are listed to work. which is cool. But is it possible to get a list of what does NOT work. Above litervollmilch mentioned it couldnt be used with ListWidget. So I am wondering what else cannot be used with it. Are there any other widgets that cannot be used with it? This will help in figuring out how to convert the blog tutorial into using mongoDB (which I hope to post when im done converting it).

either way, thanks for the extension.

Really fantastic extension.But I suffer some problems

When read data,it works fine:




$query = array('mykey'=> 'abcdefg');

$result = Transmission::model()->findAll($query);

print_r($result);



returns:




Array

(

    [0] => Transmission Object

        (

            [_document:protected] => Array

                (

                    [mykey] => abcdefg

                    [myvalue] => testvalue

                    [_id] => MongoId Object

                        (

                        )

 

                )

 

            [_id:private] => 

            [_new:private] => 

            [_flatAttributes:private] => 

            [_errors:private] => Array

                (

                )

 

            [_validators:private] => 

            [_scenario:private] => 

            [_e:private] => 

            [_m:private] => 

        )

 

    [1] => Transmission Object

        (

            [_document:protected] => Array

                (

                    [tmykey=> abcdefg

                    [myvalue] => testvalue

                    [_id] => MongoId Object

                        (

                        )

                )

 

            [_id:private] => 

            [_new:private] => 

            [_flatAttributes:private] => 

            [_errors:private] => Array

                (

                )

 

            [_validators:private] => 

            [_scenario:private] => 

            [_e:private] => 

            [_m:private] => 

        )

)




But when I try to delete the document,it go wrong:




$key ='abcdefg';

$query = array('mykey'=> 'abcdefg');

$model = Transmission::model()->findAll($query);

$model->delete();



Php told me "Call to a member function delete() on a non-object"?

How to delete documents or duplicated documents?

findAll() returns an array. You can use find() to return a single model or deleteAll() to delete all models matching your criteria.

Sander’s answer was right, you can’t delete directly if you use findAll() method. You need to iterate and delete it one by one like this:


$items=YourModel::model()->findAll();


foreach($items as $item){

$item->delete();

}

Unfortunately my extension haven’t support yet for deleteAll() method. I forgot this important feature. Will be plan to implement it soon. Thanks for remind me.

Thanks Sander and Tyohan!! ;D :lol:

Oh,unfortunately,I got some new problem… :-[

I’m using Yii 1.1.4,when I use foreach to delete each of the queried items return by findAll(),another exception occured.




CException


Description


MyModel does not have a method named "deleteByPk".


Source File


/data/yii/framework/base/CComponent.php(266)



What shall I do…

Not all method in ActiveRecord supported by this extension. Will try to cover it all. Please go to github repo for this extension and create new ticket. Thanks.