This evening I started work on an active record inspired library for interacting with MongoDB via a CodeIgniter library.
So far I’ve got searching and inserting working. Updating and deleting are going to take more time because they’re a bit trickier.
What this means is you can easily work with a database collection like so:
$this->mongo_db->where_gte('age', 18)->where(array('country' => 'UK', 'can_drink' => TRUE))->get('people');
Or:
$this->mongo_db->get_where('posts', array('title' => 'Hello, World!');
Or just:
$this->mongo_db->get('sales');
I’ve created a repository on Bitbucket located at http://bitbucket.org/alexbilbie/codeigniter-mongo-library. If you have a look at the README file there is an overview of what is there so far and also what needs doing (and some maybes!).
Hope people find it useful.
You rock! Thanks for putting this together and make it available for everyone to use.
Hi
You can add an example to use in Geospatial Indexing
By using the functions:
Where_near
and
Set_index
Thanks for your help
Moshe
are you aware of the library that was written by Kyle?
http://github.com/kyledye/MongoDB-CodeIgniter-Driver
Not sure he is still pursuing this – but maybe his code is an inspiration?
Good luck and looking forward to see more of this driver!
His code is a much improved fork of mine. I’m going to merge it back in to mine soon. Thanks
[…] Netbeans 6.8 y como nuestro proyecto estaba realizado en CodeIgniter (PHP), descargamos una librería realizada por Alex Bilbie que nos facilita mucho la tarea de programación. Esta librería es muy fácil de instalar y de […]
[…] vez dicho esto, veamos algunos ejemplos de consultas realizadas con la librería de mongodb para codeigniter sobre la colección de una […]
Hello ,
thanks for the post and the library, how can i use update function to update collections with nested arrays
for example
db.blog.posts.update({“title” : “A blog post”}, {$push : {“comments” :
{“name” : “joe”, “email” : “joe@example.com”, “content” : “nice post.”}}})
how can i do it with the library ?
if i want to push more comments to the same post
would you please give me example like
$this->mongo_db->update(‘posts’ ,$data= array(‘name’ => ‘test’ ), array(‘$push’ =>$comments));
Regards
Hello I’ll give another full example and i don’t know where is the problem
I have this collection
Array (4)
(
| [‘conv_date’] = String(21) “2010-11-24 09: 37: 14”
| [‘conv_id’] = Integer(1) 1
| [‘conv_title’] = String(11) “the title 2”
| [‘messages’] => Array (2)
| (
| | [‘0’] => Array (7)
| | (
| | | [‘attch_id’] = Integer(1) 0
| | | [‘msg_attch_type’] = NULL(0) NULL
| | | [‘msg_body’] = String(17) “this is msg2 body”
| | | [‘msg_date’] = String(21) “2010-11-24 09: 37: 14”
| | | [‘msg_id’] = Integer(1) 1
| | | [‘msg_title’] = String(11) “the title 2”
| | | [‘sender_id’] = Integer(2) 19
| | )
| | [‘1’] => Array (2)
| | (
| | | [‘msg_id’] = Float(1) 3
| | | [‘msg_title’] = String(15) “this is title 3”
| | )
| )
)
and i can insert new message to messages array by using the terminal with this command
db.msgs_conv.update({‘conv_id’:1},{$push : {‘messages’:{‘msg_id’:3,’msg_title’:’this is title 3′}}})
and every thing working fine
i don’t know how to do the same with your library
$this->mongo_db->update(‘msgs_conv’,array(‘conv_id’ => 1), array(‘$push’ =>’messages’,$message));
i don’t know why it’s not working
Hello,
I got it after reading the library source code 🙂
update function for $set , i created new one for $push and worked fine 🙂
Regards
[…] В заключение хочу оставить еще одну ссылку, откуда я и «одолжил» весь процесс установки MongoDB – в довесок там имеются примеры по работе с MongoDB в CodeIngiter (статья на английском): http://alexbilbie.blogs.lincoln.ac.uk/2010/04/17/a-codeigniter-active-record-library-for-mongodb/ […]
A CodeIgniter active record library for MongoDB…
This evening I started work on an active record inspired library for interacting with MongoDB via a CodeIgniter library. So far I’ve got searching and inserting working. Updating and deleting are going to take more time because they’re a bit trickier….
Wow, this is really useful. Thanks for taking the time! Does this work with the new CodeIgniter 2.0?