Yii Framework Forum: MongoRecord extensions - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

MongoRecord extensions Active Record extensions for MongoDb

#1 User is offline   tyohan 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 49
  • Joined: 08-October 08
  • Location:Bandung, Indonesia

Posted 23 September 2010 - 12:35 PM

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.yiiframew...on/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.
----------------------------------------------------------------------------------

http://www.thinkrooms.com - Application Development Studio

http://rserve.me - Realtime Reservation Platform

----------------------------------------------------------------------------------
0

#2 User is offline   samdark 

  • Having fun
  • Yii
  • Group: Yii Dev Team
  • Posts: 4,510
  • Joined: 17-January 09
  • Location:Russia

Posted 23 September 2010 - 01:28 PM

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.c.../storages/mongo
0

#3 User is offline   imehesz 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 716
  • Joined: 13-June 09
  • Location:Jacksonville, FL

Posted 23 September 2010 - 09:59 PM

hi,

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

keep it up,

--iM
It’s done, the great act of creation.
The maker rests. The wheel’s in motion.
-- Imre Madách

check out Yii2 Theme Factory at http://yii2.themefactory.net
0

#4 User is offline   tyohan 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 49
  • Joined: 08-October 08
  • Location:Bandung, Indonesia

Posted 23 September 2010 - 11:34 PM

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

http://www.thinkrooms.com - Application Development Studio

http://rserve.me - Realtime Reservation Platform

----------------------------------------------------------------------------------
0

#5 User is offline   JoaoJose 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 1
  • Joined: 29-September 10

Posted 29 September 2010 - 04:12 AM

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.
0

#6 User is offline   tyohan 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 49
  • Joined: 08-October 08
  • Location:Bandung, Indonesia

Posted 29 September 2010 - 07:17 PM

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.
----------------------------------------------------------------------------------

http://www.thinkrooms.com - Application Development Studio

http://rserve.me - Realtime Reservation Platform

----------------------------------------------------------------------------------
0

#7 User is offline   ironwolf 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 5
  • Joined: 08-August 09

Posted 07 October 2010 - 01:37 PM

@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..
0

#8 User is offline   tyohan 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 49
  • Joined: 08-October 08
  • Location:Bandung, Indonesia

Posted 08 October 2010 - 10:17 PM

View Postironwolf, on 07 October 2010 - 01:37 PM, said:

@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,
----------------------------------------------------------------------------------

http://www.thinkrooms.com - Application Development Studio

http://rserve.me - Realtime Reservation Platform

----------------------------------------------------------------------------------
0

#9 User is offline   litervollmilch 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 21-October 10
  • Location:Karlsruhe, Germany

Posted 22 October 2010 - 04:03 AM

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)
0

#10 User is offline   tyohan 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 49
  • Joined: 08-October 08
  • Location:Bandung, Indonesia

Posted 05 November 2010 - 09:38 PM

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

http://www.thinkrooms.com - Application Development Studio

http://rserve.me - Realtime Reservation Platform

----------------------------------------------------------------------------------
0

#11 User is offline   litervollmilch 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 21-October 10
  • Location:Karlsruhe, Germany

Posted 08 November 2010 - 09:28 AM

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

#12 User is offline   Shawn McElroy 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 4
  • Joined: 28-October 10
  • Location:California, USA

Posted 09 November 2010 - 04:54 AM

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:

https://github.com/crodas/ActiveMongo

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.
0

#13 User is offline   amazergling 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 12
  • Joined: 19-October 10

Posted 23 November 2010 - 04:59 AM

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?
0

#14 User is offline   Sander 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 169
  • Joined: 03-November 09
  • Location:Amsterdam, Netherlands

Posted 23 November 2010 - 05:03 AM

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

#15 User is offline   tyohan 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 49
  • Joined: 08-October 08
  • Location:Bandung, Indonesia

Posted 23 November 2010 - 08:50 PM

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.
----------------------------------------------------------------------------------

http://www.thinkrooms.com - Application Development Studio

http://rserve.me - Realtime Reservation Platform

----------------------------------------------------------------------------------
0

#16 User is offline   amazergling 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 12
  • Joined: 19-October 10

Posted 24 November 2010 - 12:54 AM

Thanks Sander and Tyohan!! ;D :lol:
0

#17 User is offline   amazergling 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 12
  • Joined: 19-October 10

Posted 24 November 2010 - 03:30 AM

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...
0

#18 User is offline   tyohan 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 49
  • Joined: 08-October 08
  • Location:Bandung, Indonesia

Posted 03 January 2011 - 01:32 AM

View Postamazergling, on 24 November 2010 - 03:30 AM, said:

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.
----------------------------------------------------------------------------------

http://www.thinkrooms.com - Application Development Studio

http://rserve.me - Realtime Reservation Platform

----------------------------------------------------------------------------------
1

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users