Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
MongoDB: Adding entries on an Array
  • I would appreciate the help here. For the purpose of this discussion I have an example here (I will use paste bin for the codes):

    http://pastebin.com/VPuyKn6W

    I am trying to produce this output:


    I understand that I need to use $push to make this work. But upon testing, it doesn't seem to do anything. I am following the instructions as prescribed in the docs, but instead of using $Id, and and using user_id for finding the document in the collection. Here is my model:


    Am I misunderstanding something, or I am not using the $push operator properly, or something to do on how I created the document in the first place?
  • Stepping away from the computer made me realize the answer.

        public static function create_mongo()
        {
            $data = array(
                'user_id'       => '123895',
                'First_Name'    => 'John',
                'Last_name'     => 'Doe',
                'sites'      => array(
                    array(
                        'title' => 'Sankaku Complex',
                        'site'  => 'http://sankakucomples.com'
                    )
                )
            );
            
            $db = Fuel\Core\Mongo_Db::instance();
            $db->insert('test_collection',$data);
        }

    sites should've be carrying an array. It was easy to miss, but it makes sense now.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion