是否有像这样抛出查询 mongoDB 的函数,$this->db->query($query)
因为我想在 codeigniter 中创建 mongoDB 执行程序,所以如果我像这样键入这个查询:
db.users.find({age:33})
... codeigniter 将该查询直接抛出到 mongodb 服务器还是有其他方法?
是否有像这样抛出查询 mongoDB 的函数,$this->db->query($query)
因为我想在 codeigniter 中创建 mongoDB 执行程序,所以如果我像这样键入这个查询:
db.users.find({age:33})
... codeigniter 将该查询直接抛出到 mongodb 服务器还是有其他方法?
您应该使用MongoDB PHP DriverMongoDB::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.
以下是您可能希望与活动记录一起使用的其他一些库: