Welcome Guest, Not a member yet? Register   Sign In
Using MongoDB with CodeIgniter
#1

[eluser]Unknown[/eluser]
I am interested in using MongoDB with CodeIgniter. I have found a driver from the web, but I am
not sure, if this is valid. Therefore, I would like to know, what driver you have used and
are there any -/+ with different drivers. Of course, I you like to have a reliable driver.
#2

[eluser]bretticus[/eluser]
Disclaimer: I have never attempted to do this before, but I think you might be going about this the wrong way.

MongoDB fits into the category of the "NOSQL" databases. Which means, there's not much point in trying to use CodeIgniter Active Record period. You could disable AR (and not load database at all) and still use Models to organize your data operations. Either by extending the Model class or by loading a MongoDB library (autoloading would probably be best in that case) and then referencing it inside your Models.

EDIT: looking at some documentation quickly would show that the "driver" mentioned at MongoDB's website, in the case of PHP, is a PHP extension. This typically means that you have to have MongoDB installed on your server (or one close by to connect to remotely) and have the PHP extension installed and loaded. From there, you use PHP MongoDB functions just like any other native PHP functions.
#3

[eluser]fedeisas[/eluser]
I heard a podcast regarding CodeIgniter and MongoDB. It seems like Alex Bilbie has explored the subject. He also mantains a Git repo with his library. You should give it a try.

http://alexbilbie.blogs.lincoln.ac.uk/20...r-mongodb/

Good luck
#4

[eluser]Stilly[/eluser]
@bretticus - why so hostile? I would assume that someone who asks specifically about MongoDB knows what a NoSQL DB is and has a good reason for using it. Did you see a lot of people asking just because the name sounds funny or something?

@svatunen - switching to a NoSQL DB is a good decision (most of the time), you are in for a bumpy ride, but it's worth it!

There are two libs out there - Alex Bilbi has a lib that works just fine and YES you can go almost like ActiveRecord. Take a look here: http://bitbucket.org/alexbilbie/codeigni.../wiki/Home

Installing this library is as simple and painless as installing MongoDB - really a piece of cake. (Don't get confused by what others say - it is really simple and a great database engine. Take this from someone who has done this before ;-) )

There is another library from Kyle - I havent seen any updates for some 5 months. It works also just fine, but is not as advanced as Alex work. You can find it here: http://github.com/kyledye/MongoDB-CodeIgniter-Driver (Edit line 707 of the lib - there is a typo - it should be $connection_string and $conn_string)

Good Luck with whatever it is that you are doing!
(you can pm me, if you want to chat about Mongo and NoSQL)

Peace and good Karma to everyone

Sven
#5

[eluser]bretticus[/eluser]
@Stilly I didn't realize I was being "hostile." But let's set a few things straight. When I found this post it was a page or two deep with 0 responses. I thought I was doing a favor (as I often do here in this forum.) @svatunen mentioned "drivers." To me that stipulates one of two things: A PHP extension or a CodeIgniter database driver (as they are called.) Because PHP extensions are not often called "drivers", I assumed @svatunen meant a CI database driver. When a post is vague, you get in the habit of assuming that there's some enlightenment to dish out (I'll tack on a "In case you didn't already know..." to my unintended condescending replies from now on to avoid offending you in the future.) Since CI database drivers abstract database functions of SQL databases, MongoDB does not need a "driver" that Active Record will work on. You seem to know a lot about NoSQL databases and I think you'd agree that you cannot think of them as typical databases. Only point I was trying to get across. I didn't say anything that was not true (your links you refer to are libraries with MongoDB functions afterall, not drivers.)

Judging by the good followups this post got, I don't think I did anything wrong. Sorry that you do.

Peace to you.
#6

[eluser]fedeisas[/eluser]
I heard recently about NOSQL DB and the concept screams FAST. But I just can't think of any scenarios where I can use it. Maybe @svatunen wanna share? Thanks!
#7

[eluser]Unknown[/eluser]
Thanks for answering! I'm sure some of you may think my name is funny, because I have
a finnish name.Smile And my last name is not a typical one here in Finland.

I will try MongoDB with my app. If I don't find a reliable solution for MondoDB with CodeIgniter,
I have to build one. That's part of a development, don't you think. I am always ready
for things that are new.
#8

[eluser]Stilly[/eluser]
Hi Everyone,

@svatunen: with "funny name" I meant "MongoDB" not your name Wink

Can you share the experiences that make you say the existing libs are not reliable? I am highly interested in any problems you encountered. (And any solutions your might have)

@fedeisas - Don't get carried away by the speed. Thats not really the point about NoSQL. If your application deals with only a million records or so you aint gonna see any increase in speed. As Bretticus has pointed out the thing about Document oriented DB's is that they are not like table oriented "classical" Databases. The SQL DB's that we have been using for the past 30 yrs or so are two-dimensional (row x column). Many NoSQL DB's are multidimensional. Just think of a record as a multidimensional array.

A record you retrieve could look like this:

Code:
[2]=>
  array(3) {
    ["_id"]=>
    object(MongoId)#19 (0) {
    }
    ["name"]=>
    string(9) "Peter Murray"
    ["c"]=>
    array(2) {
      ["tel1"]=>
      string(6) "555123456"
      ["tel2"]=>
      string(6) "555456123"
    }
  }

This comes in handy if you have changing db structure or any kind of social network application and the typical queries that your run in such applications. Other NoSQL DBs don't allow this. They are just key:value driven, but allow you to retrieve results from billions of records in time critical enviroments.

My personal rule of thumb is:

When you know the structure of the data before hand and you are dealing only with one company or entity data - stay with SQL. Thats proven and rock solid. But if you cant predict the data structure or if the data can multiply each other into billions - it might be worth to take a look on some NoSQL solutions.

So it's not like "Replace MySQL with MongoDB and go faster" - it's way more complicated then that. DB's worth looking into are Cassandra (thats the DB behind Facebook) which allows for instance 100 million picture uploads per day (remember: Pictures get tagged, commented on etc etc) - so simply stuff no SQL DB can do. Others are CouchDB, Googles BigTable, Amazons SimpleDB and a dozen or so more.

@Bretticus: Even if it's technically not a "driver" but a library, who cares? You can go on coding (almost) the same way you did before. Sure it's gonna be bumpy here and there and stuff will work different, but given that you switched from two-dimensional to multidimensional databases it ain't gonna get any smoother then this when you think in terms of transition. Even the best driver won't give you $this->db->join() if the DB doesn't have joints. [I am no php crack, but isn't PECL an extension to PHP? The libs I mentioned use the PHP Mongo PECL http://www.php5.org/intro.mongo.php]

Personally I find the transition in term of thinking of the database architecture way more irritating and challenging then the code level.

hey, and sorry if I misread your posting (hostility) - didn't mean to offend you.

Good luck everyone

Sven
#9

[eluser]fedeisas[/eluser]
[quote author="Stilly" date="1286578725"]Hi Everyone,

@fedeisas - Don't get carried away by the speed. Thats not really the point about NoSQL. If your application deals with only a million records or so you aint gonna see any increase in speed. As Bretticus has pointed out the thing about Document oriented DB's is that they are not like table oriented "classical" Databases. The SQL DB's that we have been using for the past 30 yrs or so are two-dimensional (row x column). Many NoSQL DB's are multidimensional. Just think of a record as a multidimensional array.
.......
[/quote]

@Stilly: Thanks for your answer. I've heard before that sites like Facebook uses MySQL for some things (let's say the user table) and Casandra (NOSQL) for things as friends sugestions. I mean, I believed that complex things to calculate, that would require MEGA complex queries, Facebook precalculate them and store them as key/value on some NOSQL systems, so they could get the data as fast as possible. But, I repeat, that's what I used to think. In my web developing experience, I have never faced that level of speed requirements (unhappily!), but I'm interested in learning new stuff Big Grin
You think I can run MongoDB on a hosted server?

Thanks for sharing
#10

[eluser]Stilly[/eluser]
Hi,

well, I think the world has changed and so have the conditions under which we develop new applications. Thats why today application tend to "age" more rapidly. You start a project and design the database, then it becomes successful and one day you have users from the UK and the ZIP field is not a varchar(5) anymore and has letters and spaces so you do your first ALTER TABLE moves and then someone from Hong Kong signs up and they don't have ZIPs at all - so you start removing the NOT NULL constraint from your database and you start having users with more then one email address and soon all your tables are all multi-to-multi-relations and you move more and more logic from the database to the code level.

We do a lot of stuff for the health care industry - one would think the field "sex" can have only "male" or "female" - but then you discover that some states now allow for "unknown"... and so forth.

Sam Hughes has written a nice article on that: "Gay marriage from a database point of view" Wink

Also a lot of todays application deal with 3 dimensional data - what is sometimes called "social graph" - Nitin Borwankar show in a very interesting blog post what this means in terms of SQL Many dimensions of "related"ness in folksonomy

There can be many good reasons to look into NoSQL Databases other then just speed. If you know your stuff with MySQL (or any other of the leading SQL engines) your data needs to become VERY VERY huge before speed becomes and issue. And if you know your stuff with MySQL very good, chances are that you do not know your stuff (yet) with MongoDB or whatever NoSQL you have choosen. And while it is easy to get help and advice on MySQL it is very difficult to find experts in say Tokyo Tyrant - So the choice of the DB should be well thought through.

I don't think you can run MongoDB on a shared hosting service - there is a lot of stuff to install and to configure and I don't think the usual pack of hosters will allow you to do that. AFAIK there is not even a handfull of Hosters who offer MongoDB at this time. Here at 40fs we run everything on a cloud so we can do pretty much whatever we want. But you can "play" with it on a local installation - I think it runs smooth even on a windows box (haven't tried yet it personally though)

If you are interested in this topic you are invited to follow 40FS on twitter - rumor has it that we will eventually have our own homepage, a blog and twitter more often (we never had actually the time to do all this moves) and there might be some useful stuff we will talk about. So join the discussion. Wink

HTH

ST




Theme © iAndrew 2016 - Forum software by © MyBB