Great!
but, how find with Regex similar with SQL params LIKE ???
I try

$this->Model->find(‘all’,
array(‘conditions’=> array(‘field’=>’/^a/’)));
don’t work !

$this->Model->query(array(…))
don’t work !

Chelder on 10/10/10

Chelder,

I think you have to use MongoRegex object:

$regex = new MongoRegex(’/^a/’);
$this->Model->find(‘all’,array(‘conditions’=> array(‘field’=>$regex)));

David on 10/11/10

Is there a better way for querying mongodb geospacial indexes than something like:

$places = $this->Model->query(array(‘geoNear’=>‘places’, ‘near’ => array(43,-79), ‘num’ => 2));

I had to add a line to the datasource:
if (is_array($result)) return $result;

to get a return value like:

Array ( [ns] => my_test.places [near] => 1001001010111101110100110000111010111101110100110000 [results] => Array ( [0] => Array ( [dis] => 0.755928373372 [obj] => Array ( [_id] => MongoId Object ( ) [content] => dskjfsadlfkjdsaflsdkjfdslkfajsldkfj [loc] => Array ( [0] => 43.6525 [1] => -79.3816667 ) ) ) ) [stats] => Array ( [time] => 0 [btreelocs] => 0 [nscanned] => 1 [objectsLoaded] => 1 [avgDistance] => 0.755928373372 [maxDistance] => 0.755928373372 ) [ok] => 1 )

Craig Garrett on 11/4/10

@Furkan Tunalı — you probably need to add extension=mongo.so to your php.ini file. i had the same error and this fixed it for me.

randy on 11/8/10

Great tutorial, I just wanted to know how to add the validation rules, like unique username for example.
This is the way that I’m doing it right now, but the unique rule doesn’t work.

Thanks!

arialva on 11/23/10

Sorry, this is the code:
var $validate = array( ‘username’ => array( ‘notempty’ => array( ‘rule’ => ‘notempty’, ‘message’ => ‘You must select an username.’ ), ‘unique’ => array( ‘rule’ => ‘isUnique’, ‘message’ => ‘Username already registered in the system.’ )), ‘password’ => array( ‘password’ => array( ‘rule’ => ‘notempty’, ‘message’ => ‘Please enter a password.’ ) ), ‘email’ => array( ‘email’ => array( ‘rule’ => ‘email’, ‘message’ => ‘Please provide your email address.’ ), ‘unique’ => array( ‘rule’ => ‘isUnique’, ‘message’ => ‘Email already registered in the system.’ ))
);

arialva on 11/23/10

arialva: Validation rules for mongo backed models, should work exactly the same for ones with SQL persistence. I didn’t notice any difference at least.

mark story on 11/27/10

I didn’t find the way to make an unique field, ‘unique’ => array( ‘rule’ => ‘isUnique’) doesn’t work for me.

arialva on 11/30/10

Thanks Mark and Yasushi Ichikaway.
You helped us a lot!!!

Daniel Costa on 11/9/11

i’m trying to get mongodb to work with cakephp. I’m not sure on where to place ichikaway’s mongodb driver for cakephp. The following is my directory structure:
under c:/websites/
I have cakephp folder and my project merry_flowers folder.

am i supposed to place the mongodb driver in cakephp/app/plugins or merry_flowers/plugins?

where am I supposed to add the database connection?
in cakephp/app/config/database.php or merry_flowers/config/database.php

Any help is much appreciated.

varai on 11/20/11

i’m trying to get mongodb to work with cakephp. I’m not sure on where to place ichikaway’s mongodb driver for cakephp. The following is my directory structure:
under c:/websites/
I have cakephp folder and my project merry_flowers folder.

am i supposed to place the mongodb driver in cakephp/app/plugins or merry_flowers/plugins?

where am I supposed to add the database connection?
in cakephp/app/config/database.php or merry_flowers/config/database.php

Any help is much appreciated.

varai on 11/20/11

How can I do if I want to connect cakephp to mongodb in other server with login and password for this database??
Thanks a lot

gounane on 11/23/11

I keep getting a memory error now that I have alot of records. I’ve tried all the memory_limit tricks but still no luck. Tried limiting my query but must be doing it wrong.

Fatal error: Allowed memory size of 262144 bytes exhausted (tried to allocate 72 bytes) in /var/www/localhost/eatsource.com/dev/plugins/mongodb/models/datasources/mongodb_source.php on line 1000

Travis on 12/17/11

How to test controller using different models some using RelationalDB other MongoDB?

I have configure one of my models to use MongoDB. This model is used by a controller that is using other models as well. Those other models are still using a relational database. It works when browsing the website.

However, i cannot make my SimpleTest on the controller to work. The testcase returns an error that it couldn’t find my mongoDB model’s table.

In the plugin source, i can find test examples that will work for my model using MongoDB. The way the RDBM and MongoDB tests are initialise is very different: one use fixture the other the ConnectionManager.

Any hint on how to initialise those controller tests?

Olivier Vernin on 1/24/12

I tried following this but for some reason I get this error:
ConnectionManager::getDataSource – Non-existent data source mongodb

I used git and cloned directly into my plugins directory, but still no joy. Does this work with Cake 1.3.7?

Bruce Martin on 2/2/12

Hi, i’m trying to use cakephp-mongo. My first step is develop ACL and Auth classes.

I want to use cakephp Auth component and Acl component but there is no code to test.

I’m newbie. :-(

Cicci Manolesta on 7/26/12

nice tutorial

Andrew struart on 7/31/12

I’m gone to inform my little brother, that he should also pay a visit this weblog on regular basis to take updated from most recent reports.

Textiles Fabric Living on 9/24/12

It is appropriate time to make a few plans for the longer term and it
is time to be happy. I’ve read this post and if I may just I desire to recommend you few attention-grabbing issues or tips. Perhaps you could write next articles referring to this article. I desire to learn more things about it!

printed coasters on 10/1/12

Does this work in cakephp 2.x? I am having a heck of a time getting my app to load the mongodb plugin. I believe I have all the right files in the right place.

D:\Apache24\htdocs\service4u_mongo\app\Plugin\Mongodb\Model\Behavior\SchemalessBehavior.php

D:\Apache24\htdocs\service4u_mongo\app\Plugin\Mongodb\Model\Behavior\SqlCompatibleBehavior.php

D:\Apache24\htdocs\service4u_mongo\app\Plugin\Mongodb\Model\Datasource\MongodbSource.php

I have “CakePlugin::load(‘Mongodb’);” in the bootstrap.php file

the error I am getting is “The application is trying to load a file from the mongodb plugin” what file is it trying to load and where do I get it from?

Thanks for the help.

Jamie on 11/8/12