它能使你的应用在操作MongoDB时保证和active record一致的风格。
1,添加Mongo_db.php 到你的 /application/libraries 文件夹 2,添加mongodb.php 到你的 /application/config 文件夹 3,更你的配置文件
你可以把它设置为autoload,也可以在你的控制器里加载它。
你可以使用codeigniter的active record的方式来操作数据库。
$this->mongo_db
->where_gte('age', 18)
->where(array(
'country' => 'UK',
'like_whisky' => TRUE
))
->get('people');
结果会返回相匹配的文档。
select 方法
- select($includes = array(), $excludes = array()) 从文档中选择某些字段或是排除那些字段,排除时第一个参数给个空数组即可
- where($wheres, $value = null) 返回同时满足wheres关联数组条件的文档
- or_where($wheres = array()) 返回满足wheres关联数组其中一个条件的文档
- where_in($field = "", $in = array()) 返回字段值在给定的数组中的文档
- where_in_all Where something is in all of an array of * something
- where_not_in Where something is not in array of something
- where_gt Where something is greater than something
- where_gte Where something is greater than or equal to something
<li>where_lt Where something is less than something</li>
<li>where_lte Where something is less than or equal to something</li>
<li>where_not_equal Where something is not equal to something</li>
<li>where_near` Where something is near to something (2d geospatial search)
order_by Order the results