We have a complex mongo configuration that looks something like:
$conf['mongodb_connections'] = array(
// this is the mongo live instance for the primary site
'default' => array(
'host' => 'host1',
'db' => 'host1_live'
),
// this is the mongo slave instance
'my_parents_slave' => array(
'host' => 'host2',
'db' => 'host2_slave'
),
// This is the mongo live instance for the secondary site
'my_parent' => array(
'host' => 'host3',
'db' => 'host3_live',
),
);
$conf['mongodb_collections'] = array(
// this set of collections need to be read from the mongo slave instance
'fields_current.my_collection' => 'my_parents_slave',
// This set of collections need to be read from the mongo live instance
'session' => 'my_parent',
'watchdog' => 'my_parent',
);
This configuration allows us to read data from the correct sources and use default mongo for storage. This configuration works great for most use cases. The problem arises when we have one query that needs to read it's data from parent sites slave mongodb and another that needs to read it's data from parent sites live mongodb. At that point we are trying to use the same collection name against two different mongodb datasources but can only have one alias in $conf['mongodb_collections'].
The attached patch introduces checking for a third argument in mongodb_collection that will allow us to effectively switch datasources.
Comments
Comment #1
cyberswat commentedComment #2
douggreen commentedsubscribing (since I wrote the original patch anyways), I'd like to get chx's input on this
Comment #3
marcingy commentedDifferent approach to the same problem. Rather than introduce a new parameter which won't work for field storage writes and deletes this patch allows for an active connection to be set in a similar way to the drupal database layer, this then means that specific queries can be targetted against different mongo colelctions.
Comment #4
chx commentedIf you are manipulating globals then why not
$GLOBALS['conf']directly?Comment #5
marcingy commentedReroll taking into account above comment which reduces the code weight some what.
Comment #6
marcingy commentedComment #7
misc commentedWhat I can see, this is committed to dev.