我正在研究如何在magento和mongodb之间集成。首先,如何连接?并执行CRUD?
p/s:我的系统正在使用mysql,我也想使用mongodb
我基于我的工作与mongo旁边magento与此功能github.com/colinmollenhour/magento-mongo
如果连接有问题,请将Mage_Core_Model_Resource中的_newConnection方法更改为:
protected function _newConnection($type, $config)
{
if ($config instanceof Mage_Core_Model_Config_Element) {
$config = $config->asArray();
}
if (!is_array($config)) {
return false;
}
$connection = false;
// try to get adapter and create connection
$className = $this->_getConnectionAdapterClassName($type);
if ($className) {
// define profiler settings
$config['profiler'] = isset($config['profiler']) && $config['profiler'] != 'false';
$connection = new $className($config);
if ($connection instanceof Varien_Db_Adapter_Interface) {
// run after initialization statements
if (!empty($config['initStatements'])) {
$connection->query($config['initStatements']);
}
} else {
$connection = false;
}
}
// try to get connection from type
if (!$connection) {
$typeInstance = $this->getConnectionTypeInstance($type);
$connection = $typeInstance->getConnection($config);
// if (!$connection instanceof Varien_Db_Adapter_Interface) {
// $connection = false;
// }
}
return $connection;
}
认为,
简单地改变连接层是行不通的。你将需要一个完整的MongoDB抽象层来取代MySQL抽象层和底层数据库。
看看https://github.com/colinmollenhour/magento-mongo,这应该能让你开始。我自己没有使用过,所以我不能保证它的质量或完整性。
PS:为什么你想要取代MySQL?除非你有很好的理由,否则我会保持默认设置,因为它可以更好地进行实战测试。