GROUP BY ($group) in MongoDB

Mongodb is not relational database, but we sometimes want to use functions similar from such databases. I wrote about JOINs in Mongo few weeks ago, but it isn’t only one option. Second and very interesting is grouping – something like GROUP BY in for example MySQL database. Do we really need grouping in Mongo? Maybe yes, maybe no, but I must implement such option for one of application modules. It isn’t difficult and we can do this very simply. Again, I will use examples from PHP and mongodb extension for this language – code should be very similar in other languages.

Continue reading “GROUP BY ($group) in MongoDB”

PHP/Mongo – Using JOIN in queries

I’ve written one post about MongoDB and PHP about creating nested set model in this database, but there is another interesting topic: using JOINs in mongo queries. Sorry, wh… what? Joining tables in non-relational database? Yes, it’s possible and we can do this to collect much more data in only one, but more complicated query. Let’s start to see how we can achieve this.

Continue reading “PHP/Mongo – Using JOIN in queries”

PHP/Mongo – Nested set model

Last time I created some structure for linking different elements from similar groups. This project needed high performance and easy way to get elements hierarchy, but changes are not often. After consideration I decided to implement nested set tree model to do this. All is based on PHP and use Mongo database and I would like to show you some basis operations with that. It can be helful in some cases, and that model is very efficient in read operations.

Continue reading “PHP/Mongo – Nested set model”