We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Save an Array on Mongo.

Hi, I'm recently was using the Phalcon Micro without problem, on my API I use Mongodb, when I need to save, update, find, etc I was using the Mongo PHP Extension without problem, right now I want to learn more I and decided to use Phalcon ODM, but right now I was unable to save an array to my mongo collection.

Here is my current simple code:

    //Unable to save data.
    $photo = array("url" => "https://xxx", "name" => "Nice", "catalog" => array("name" => "TC", "id" => 2 ));
    $photos = new photos; 
    $photos->save($photo);
    // Can save data using this pattern
    $photos = new photos; 
    $photos->url = "http//xxx";
    $photos->name = "Nice";
    $photos->catalog = array("name" => "TC", "id" => 2 );
    $photos->save();

I'm missing something because using the php mongo extension can save the array without problem.

Thank you in advance!



145.0k
Accepted
answer

Yea. Mongo is just diffrent than model. Doesn't have option to save like this.



4.1k

Yea. Mongo is just diffrent than model. Doesn't have option to save like this.

Thank you for your response, so, is not another way to accomplish this? And what about the performance, what do you recommend use Phalcon ODM or just continue using the PHP Mongo Extesion.

Best Regards.

edited Jan '17

But phalcon needs php mongo extension anyway so i don't understand your question. Phalcon ODM just provides classes with methods to work with mongo easier and simpler. You can always create NFR/PR for mongo on github.



4.1k

Now I get it, I thought Phalcon could do the job without the mongo extension, Now this comments clarified my doubts about that. Thank you like always. Have a nice day. Best Regards.

But phalcon needs php mongo extension anyway so i don't understand your question. Phalcon ODM just provides classes with methods to work with mongo easier and simpler. You can always create NFR/PR for mongo on github.