use*_*073 5 php codeigniter mongodb
有没有像这样抛出查询mongoDB的函数,$this->db->query($query)因为我想在codeigniter中创建mongoDB执行器,所以如果我输入这样的查询:
db.users.find({age:33})
Run Code Online (Sandbox Code Playgroud)
... codeigniter直接向mongodb服务器抛出该查询还是有另一种方式?
您应该使用MongoDB PHP Driver将MongoDB::command()此类数据库命令传递到 mongodb 服务器。
在 CodeIgniter 中,您可以使用一些社区构建的 MongoDB 库。由于我检查了几乎所有这些,因此请采纳我的建议并使用CodeIgniter MongoDB Active Record。这是示例代码:
<?php
// Somewhere in your model, controller, etc.
// Load MongoDB library
$this->load->library('mongo_db');
// Query MongoDB: Active document library usage example
$docs = $this->mongo_db->where('age', '33')->get('collection_name_here');
// Query MongoDB: Command usage example
$docs = $this->mongo_db->command(array(
'geoNear' => 'buildings',
'near' => array(53.228482, -0.547847),
'num' => 10,
'nearSphere' => TRUE,
));
// Theme results, pass to the view, etc.
Run Code Online (Sandbox Code Playgroud)
以下是您可能希望与活动记录库一起使用的其他一些库:
| 归档时间: |
|
| 查看次数: |
7931 次 |
| 最近记录: |