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

cyberswat’s picture

Status: Active » Needs review
StatusFileSize
new1.21 KB
douggreen’s picture

subscribing (since I wrote the original patch anyways), I'd like to get chx's input on this

marcingy’s picture

StatusFileSize
new1.92 KB

Different 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.

chx’s picture

Status: Needs review » Needs work

If you are manipulating globals then why not $GLOBALS['conf'] directly?

marcingy’s picture

StatusFileSize
new850 bytes

Reroll taking into account above comment which reduces the code weight some what.

marcingy’s picture

Status: Needs work » Needs review
misc’s picture

Status: Needs review » Fixed

What I can see, this is committed to dev.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.