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

Tutorials or example apps with mongodb

Greetings,

I am most interested in creating a couple apps with Phalcon using MongoDB and was hoping that there would be a couple tutorials and example apps built with this. I have not seen any and thought I would throw out a request for this.

Perhaps even taking Invo and making a mongodb version? Actually anything that gives a good overview of using mongodb with CRUD in Phalcon would be a big help to others.



3.6k

It is not much different. You just have to:

  1. Set up a MongoClient connection and CollectionManager
  2. Your models should extend \Phalcon\Mvc\Collection

If there are more people who think that it will be useful, I can convert invo to use mongodb this weekend.

@lobostome cool! It will be great!



29.4k

+1 The most interesting moment is relations between models. Also it would be nice to see the solution of collections which consists of several models, because it's not implemented in the core https://github.com/phalcon/cphalcon/issues/578

Perhaps others will also be interested in some tutorials like this...

I was wondering if there are plans on further dev regarding MongoDB and Phalcon. Actually I am not clear on how far the current dev is on all this. i.e. Support of:

  • Aggregate/group support
  • Indexes
  • GridFS

Are any of these features already supported or is there plans for the future?

After further review of the docs for MongoCollection, I see that indexes and groups are indeed implemented. VERY COOL!

Looks like the only thing that is not is usage of GridFS ?

Also, I ended up hijacking my own thread here from the original suggestion of asking for tutorials that include using MongoDB. Still think that is a good idea. :)

Well, this will be my last plug requesting at least a demo app with full CRUD/Sessions/User Auth showing usage of Mongodb.

One of the things that can really help the popularity of this framework is the fact that Mongodb is part of the core framework and not some added on module like other frameworks implement. I really think if I have some actual demo's showing this would help me and others that I know who are interested in Mongodb see the ease of development with Phalcon.

So, here is hoping for Mongodb demo's in the future! :)



98.9k

@Dave, I'm working in a sample application using Phalcon-Micro+Mongo, it's a very early stage, but it could help you to understand the basic setup.

The database has more than 800.000 documents, the only available option shows a geographical chart showing the results of a "count" aggregation.

The database is attached as: stats.zip



3.6k

@Dave I am also working on the invo application. Too many deadlines last couple of weeks, and I could not finish it.



3.6k

@Dave Nosker+ Here is partial implementation of invo (user registration and login). It features establishing mongo connection, creating collection manager, saving data (Register), querying for data (Login), custom validator for model (UniqueNoSQLValidator), and defining events for a model (validation and beforeCreate).

https://github.com/lobostome/invo-phalcon-mongodb

I will keep updating whenever I get a chance.

@lobostome - Thanks a bunch! I will learn from it and direct others that I know to do the same.



3.6k

@Dave I am glad I can help. In the meantime, I added CRUD for product types, sorting by field, and aggregation.

Hi I am also looking out for a sample CRUD example which uses MongoDB, specifically I want example on how to get the pagination working with MongoDB.

@Phalcon, please let me know if you have any sample CRUD with pagination working for Phalcon-MongoDB.



785
edited Mar '14

controller:

<?php
public function indexAction()
    {
        $currentPage = $this->request->getQuery('page', 'int');
        $users = Users::find();

        $paginator = new \Phalcon\Paginator\Adapter\NativeArray(
            array(
                "data" => $users,
                "limit"=> 1,
                "page" => $currentPage
            )
        );

        $page = $paginator->getPaginate();
        $this->view->setVar("page", $page);
    }
?>

in view:

<html>
<table>
    <tr>
        <th>Id</th>
        <th>Name</th>
        <th>Type</th>
    </tr>
    <?php foreach ($page->items as $item) { ?>
        <tr>
            <td><?php echo $item->_id; ?></td>
            <td><?php echo $item->name; ?></td>
        </tr>
    <?php } ?>
</table>

<a href="/index/index">First</a>
<a href="/index/index?page=<?= $page->before; ?>">Previous</a>
<a href="/index/index?page=<?= $page->next; ?>">Next</a>
<a href="/index/index?page=<?= $page->last; ?>">Last</a>

<?php echo "You are in page ", $page->current, " of ", $page->total_pages; ?>
</html>


3.8k

I could not find the stats.zip