How can I use MongoDB in Kohana?

∥☆過路亽.° 提交于 2019-12-10 11:00:52

问题


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.



来源:https://stackoverflow.com/questions/10426796/how-can-i-use-mongodb-in-kohana

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!