How can I use MongoDB in Kohana?

2019-05-25 01:41发布

问题:

Please, give me some startup guidance on how to use MongoDB in Kohana[v3.2].

I downloaded the Kohana Module from Mongo Module for kohana and have set up the MongoDB driver for PHP. Now I'm trying to create a new database and to save a record into it.

回答1:

You Don't actually need the MangoDB module for Kohana that you linked to. You can just use PHP's MongoDB Native Driver. The mongo query language is pretty simple, if you know some MySQL then this page would help...

http://www.php.net/manual/en/mongo.sqltomongo.php

Here is an example using the driver, it connects, starts and inserts into a new collection and then selects the all the data in the collection...

$m = new Mongo();

$db = $m->my_database;

$db->my_new_collection->insert(array("a" => 1, "b" => 1));

$found_data = $db->my_new_collection->find();

See more at http://www.php.net/manual/en/mongo.manual.php

If you want to use MangoDB then I suggest reading the code and checking the kohana forums for info on it.

http://forum.kohanaframework.org/search?Search=mangodb



回答2:

What have you tried so far? StackOverflow is for when you are stuck on a problem and have tried everything you can. It isn't a place to come to just because you are learning new technology and can't be bothered to do some learning by yourself

Buy a book; search the MongoDB documentation; use Google and try some things. You may surprise yourself and get things working without any help and, if you do, you will have learnt more than if you got someone else to do the hard work for you.