Mongo change collection in model FIND

How to change dynamically at runtime the collection?

<?php 

class Robots extends \Phalcon\Mvc\Collection {

    $_sourceName = 'robots';

    function setSource($xpto){

                $this->_sourceName = 'robots_'.$xpto;

    }

    function getSource(){

                return $this->_sourceName;
    }
    function findConditions($xpto, $conditions){
                $this->setSource($xpto);
                return $this->find(['conditions' => $conditions];)
    }
}
edited Sep '15

I try and does not work

<?php 

public function findByOwner($xpto) {
        $model = new Schema();
        $model->setSource($appId);
        $model->find();
    }



3.6k

From the Collection source, it doesn't seem you need to use setSource. Find() calls getSource() so just use that.

<?php 

class Robots extends \Phalcon\Mvc\Collection {

    private $sourceName = 'robots';

    function getSource(){

                return $this->sourceName;
    }
    function findConditions($xpto, $conditions){
                $this->sourceName = $xpto;
                return $this->find(['conditions' => $conditions]);
    }
}

Hello

I have the same problem with mongo db but this example will help for runtime you can visit https://zappysys.com/blog/ssis-loading-data-into-mongodb-upsert-update-delete-insert/ I hope this will be help.